Chapter 30 Multithreading and Parallel Programming
1) Thread Concepts
You can create additional threads to run concurrent tasks in the program. In Java, each task is an instance of theRunnable interface, also called a runnable object. A thread is essentially an object that facilitates the execution of a task.
1. template for developing task class
2. Exercise 30.5
Answer:
(a) newTest() is recursively called inside the constructor. To fix it, delete the highlighted line and use new Thread(this).start().
(b) An illegaljava.lang.IllegalThreadStateException may be thrown because you just started thread and thread might have not yet finished before you start it again. To fixit, delete one t.start().
Look at the definition of this key word:
The keyword this can be used to refer to the calling object. It can also be used inside a constructor to invoke another constructor of the same class.