O'Reilly logo

Beginning Java 8 Language Features: Lambda Expressions, Inner Classes, Th reads, I/O, Collections,and Streams by Kishori Sharan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 +                                         ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required