@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"); }
@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; }