@Override public void run() { while (!stopped.get()) { try { task.call(); counter.incrementAndGet(); } catch (Error e) { exception.set(e); stopped.set(true); } catch (Exception e) { exception.set(e); stopped.set(true); } } } };
long stop = millis + System.currentTimeMillis(); while (System.currentTimeMillis() < stop) { task.call(); counter.incrementAndGet();