Have you tried compiling it yourself? What happens when you do? What happens when you run it? I bet you get an IllegalThreadStateException.
Joined: Nov 16, 2000
Yes it does, but I cannot understand why. Could you pleasee elaborate.
Joined: Jan 07, 2002
Look at the Thread class javadocs. Basically, you can only call start() on a Thread object one time. Once the Thread is started, you can't call start() again. This implies you can't reuse a Thread object. Once it completes its task, you must instantiate a new THread object if you want to run it again.
In your program, if you really want 3 seperate threads running, you need to create 3 different Thread objects, and call start() on each of the Thread objects.
Hi Rob! This statement is not true : "This implies you can't reuse a Thread object. " You can re-use a Thread object but you cannot re-run the thread, i.e invoke Thread.start() again. You can invoke Thread.run() or other methods in the class derived from the thread. Brian [ February 11, 2002: Message edited by: Brian Lugo ]
Brian, what you are trying to say is that we can USE (not re-use) a Thread object once it has run. What Rob was saying is that a Thread object will only be able to run once and that's it. After its death, you can only invoke its methods (but not start() again). Pay attention to the terminology you use, it is very important to be 200% accurate when claiming things... So I would modify your statement
You can re-use a Thread object but you cannot re-run the thread, i.e invoke Thread.start() again.
as follows: You can use a Thread object but you cannot re-start the thread, i.e. invoke start() on the thread instance again. (start() is not a static method)
I know you know the concept, so no hard feelings. (I know I'm one hell of a picky guy ) [ February 11, 2002: Message edited by: Valentin Crettaz ]