Listing 6-47. A Runnable Task
// RunnableTask.javapackage com.jdojo.threads;import java.util.Random;public class RunnableTask implements Runnable { private int taskId; private int loopCounter; private Random random = new Random(); public RunnableTask(int taskId, int loopCounter) { this.taskId = taskId; this.loopCounter = loopCounter; } public void run() { for(int i = 1; i <= loopCounter; i++) { try { int sleepTime = random.nextInt(10) + 1; System.out.println("Task #" + this.taskId + " - Iteration #" + i + ...
Get Beginning Java 8 Language Features: Lambda Expressions, Inner Classes, Th reads, I/O, Collections,and Streams now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.