void stop() {
   if (started.compareAndSet(true, false)) {
     try {
       thread.isRunning = false;
       thread.interrupt();
       thread.join(TimeUnit.SECONDS.toMillis(5));
     } catch (InterruptedException e) {
       EmptyStatement.ignore(e);
     }
   }
 }
Exemplo n.º 2
0
    @Override
    public void run() {
      setProgress((int) ((System.currentTimeMillis() - start) * 100 / time));
      stepsCurrent = 0;
      pi = 0;

      for (PerformanceThread p : threads) {
        pi += p.getPi();
        stepsCurrent += p.getLastSteps();
      }

      pi = pi / threadCount;
      publish(pi + " @ " + (stepsCurrent / intervall) + " steps / ms");
    }
Exemplo n.º 3
0
  @Override
  public Double doInBackground() {
    LOG.debug("Building threads");
    for (int i = 0; i < threadCount; i++) {
      threads.add(new PerformanceThread());
    }

    time = time * 1000;

    double stepsPerSecondAll = 0;
    double pi = 0;
    long start = System.currentTimeMillis();
    long stepsOverall = 0;

    Timer timer = new Timer();
    timer.schedule(new PerformanceTimerTask(start), 0, intervall);

    LOG.debug("starting threads");
    for (PerformanceThread p : threads) {
      p.start();
    }

    while ((System.currentTimeMillis() - start < time) && !isCancelled()) {
      try {
        Thread.sleep(intervall / 10);
      } catch (InterruptedException ex) {
        LOG.debug("", ex);
      }
    }

    timer.cancel();
    setProgress(100);

    LOG.debug("Interrupting threads");
    for (PerformanceThread p : threads) {
      p.interrupt();
      stepsOverall += p.getSteps();
      pi += p.getPi();
    }

    pi = pi / threadCount;
    stepsPerSecondAll = stepsOverall / (System.currentTimeMillis() - start);
    publish(pi + " ( " + stepsPerSecondAll + " steps per millisecond )");
    return pi;
  }
 String getPerformanceNumbers() {
   if (started.get()) {
     return thread.getPerformanceNumbers();
   }
   return "";
 }
 void logDetailedPerformanceInfo(int duration) {
   if (started.get()) {
     thread.logDetailedPerformanceInfo(duration);
   }
 }
 void start() {
   if (started.compareAndSet(false, true)) {
     thread.start();
   }
 }