Beispiel #1
0
  @Override
  protected void cleanUpExamples(int epoch) {
    //		int n=0;
    for (int k = 0; k < nthreads; k++) {
      if (currentTrainingRun.queues.get(k).size() > 0) {
        //				n++;
        TrainerThread t = new TrainerThread(currentTrainingRun.queues.get(k), k);
        Thread th = new Thread(t, "xthread " + k);
        th.setDaemon(true);
        th.setUncaughtExceptionHandler(t);

        if (log.isDebugEnabled()) log.debug("Starting thread " + k);
        currentTrainingRun.threads.add(th);
        th.start();
      }
    }

    while (currentTrainingRun.threads.size() > 0) {
      try {
        Thread th = currentTrainingRun.threads.get(0);
        if (log.isDebugEnabled()) log.debug("Joining thread " + th.getName());
        th.join(); // will finish adding any new threads in uncaughtexceptionhandlers before
        // returning
        currentTrainingRun.threads.remove(0);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    currentTrainingRun.threads = null;
  }
Beispiel #2
0
  @Override
  protected void setUpExamples(int epoch, Collection<PosNegRWExample> examples) {
    super.setUpExamples(epoch, examples);
    if (currentTrainingRun.threads != null) {
      throw new IllegalStateException(
          "template called out of order! Must clean up last example set using cleanUpExamples()");
    }

    currentTrainingRun.threads = new ArrayList<Thread>();
    currentTrainingRun.queues.clear();
    for (int k = 0; k < nthreads; k++) {
      currentTrainingRun.queues.add(new ArrayList<TrainerExample>());
    }
  }