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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.