Samstag, 29. November 2008

EE3206/EE5805 Java Threads-1

EE3206/ EE5805 Java Programming and Applications

notes on Threads from "The Java Programming Language, 3rd" p 229-231:

Creating Threads

1. To create a thread of control, you start by crating a Thread object:

Thread student = new Thread();

2. When the thread is ready to run, you invoke its start() method. The start() method spawns a new thread of control based on the data in the Thread object, then returns.

3. The JVM invokes the new thread's run() method, making the thread active. You can invoke start() only ONCE for each thread--invoking it again results in an
IllegalThreadStateException.

4. When a thread's run() method returns, the thread has exited. You can cease running a thread by invoking its interrupt() method.

5. To get a thread that does something, you must either extend Thread to provide a new method or create a Runnable object and pass it to the thread's constructor.

6. You can get the Thread object for the currently running thread by invoking the static method Thread.currentThread.



Keine Kommentare: