code: @Override
      public void applyUpdate(StepFunction function, INDArray params, INDArray grad, boolean isFinalStep) {
  
          try {
              updatesLock.readLock().lock();
  
              firstOne.compareAndSet(-1L, Thread.currentThread().getId());
  
              if (hasSomething.get())
                  function.step(params, updates);
  
              barrier.await();
              if (firstOne.get() == Thread.currentThread().getId()) {
                  // one thread just nullifies this array
                  updates.assign(0.0);
                  hasSomething.set(false);
  
                  firstOne.set(-1L);
              }
  
              updatesLock.readLock().unlock();
              barrier.await();
          } catch (InterruptedException e) {
              Thread.currentThread().interrupt();
              throw new RuntimeException(e);
          } catch (BrokenBarrierException e) {
              throw new RuntimeException(e);
          }
      }
docs: This method applies accumulated updates via given StepFunction
  
  @param function
  @param params