Meaningless Drivel is fun!
The moose likes Threads and Synchronization and the fly likes start the thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "start the thread" Watch "start the thread" New topic

start the thread

SrinivasaRao Swarna

Joined: Sep 17, 2006
Posts: 20
Hi Friends,

We can start thread two times ?is it posible?How can do?

Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

This is what the javadoc of start method says:

It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.

IllegalThreadStateException - if the thread was already started.

It is always recommended to RTFM (Read the f#$%ing manual)

apigee, a better way to API!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Here's what you can do instead. Put your code in a Runnable and run it on two threads:

See how we executed the run() method in MyRunnable twice? Is that the effect you wanted? If so, we can also do some neat stuff with Thread pools.
[ September 12, 2007: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
paritosh ranjan
Ranch Hand

Joined: Aug 24, 2007
Posts: 62
threads are same as human beings
they take birth once and die once
we never take birth twice
same is the case with threads
once the thread is started the thread can't be started again
even after the thread finishes executing and reaches dead state
start() can't be called on the dead thread
like once humans are dead,they can't be made alive
if you try to start the same thread again,you will get a IllegalStateException
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by paritosh ranjan:
threads are same as human beings
they take birth once and die once

Have you never seen Dawn (or Shaun) of the Dead?!

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
paritosh ranjan
Ranch Hand

Joined: Aug 24, 2007
Posts: 62
what does that mean??
pete stein

Joined: Feb 23, 2007
Posts: 1561
Have a look at the wikipedia articles on Dawn of the Dead and its comedy counterpart, Shaun of the Dead and you will understand what this all means: poor joke.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: start the thread
jQuery in Action, 3rd edition