• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IllegalThreadStateException

 
ahsan mir
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest to use a threadpool instead.
If you are using jdk5. Threadpools are readily available as part of the jdk.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic