Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IllegalThreadStateException

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic