This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

IllegalThreadStateException  RSS feed

 
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
 
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.
 
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
Boost this thread!