@Override public void execute(ContinueCallback callback) { int sleepMs = ThreadLocalRandom.current().nextInt(1, 100); System.out.println("[" + Thread.currentThread() + "]: BEGIN async task of " + id + " (will sleep for " + sleepMs + " ms)"); try { Thread.sleep(sleepMs); var.set(sleepMs); if (ThreadLocalRandom.current().nextDouble() <= SPAWN_CHANCE) { // spawn a new task! spawnNewTask(context, workQueue); } } catch (InterruptedException e) { e.printStackTrace(); } finally { System.out.println("[" + Thread.currentThread() + "]: END async task of " + id); callback.finished(); } } }
@Override public void execute(ContinueCallback callback) { System.out.println("in task"); callback.finished(); } });