Explanation
As soon as you click the "Start" button, the program creates a new
thread to call the dangerousLoop() method
of remote object. Now, if you click the "Exit" button, the application
has the opportunity to notice the event, and process the "Exit" action.
Run the program, and see the difference.
Figure 10.2

The
java.lang.Thread Class
public class Thread extends Object
implements Runnable
Constructor
- public Thread(Runnable
target) - Allocates a new
Thread
object.
Methods
- public void run()
- This method does nothing and returns. Subclasses should override
this method.
- public void start()
- Registers the thread with the thread scheduler.

There are two ways to create a thread. One is to declare a class to
be a subclass of Thread class.
The other way to create a thread is to declare a class that implements
the Runnable interface.
|