jQuery in Action, 3rd edition
The moose likes Threads and Synchronization and the fly likes IllegalThreadStateException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "IllegalThreadStateException" Watch "IllegalThreadStateException" New topic


ahsan mir
Ranch Hand

Joined: Jul 17, 2006
Posts: 42
I have just started threads ,and using them with database calls in my swing application. I am getting the above exception if the same thread is called more than once(this happens if a value is not valid for example, so stays in the same frame/class). Any suggestions how to get round it.

any help would be appreciated
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
You can't run a Thread more than once.

Put the work into a Runnable, then create a new Thread using that Runnable, every time you want to run it.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

I would suggest to use a threadpool instead.
If you are using jdk5. Threadpools are readily available as part of the jdk.

apigee, a better way to API!
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
A thread pool might be a good optimisation for this case, though there is insufficient information to know. However, if the original poster is at the position of not really yet knowing how to use threads at all, then adding thread pools into the equation is probably a bad idea. One step at a time!

Most applications don't need optimising for speed at all. Most applications that do need optimising for speed don't need optimising for thread usage. Most applications that do need optimising for thread usage only need it in a fraction of all thread call-sites.

That said, once one has added thread pooling to an application, one may as well use it widely. I do!
[ June 14, 2007: Message edited by: Peter Chase ]
I agree. Here's the link: http://aspose.com/file-tools
subject: IllegalThreadStateException
It's not a secret anymore!