• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Thread Performance Question

 
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are going to have a task which occurs quite often but at irregular intervals are you better off keeping a single thread running or spawning a new thread to perform each task?
Does creating a new thread each time suck up more memory and processor than a single thread which runs for the life of the application?
How would you mesasure this?
Thank you,
Drew
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are going to have a task which occurs quite often but at irregular intervals are you better off keeping a single thread running or spawning a new thread to perform each task?
I would probably do it all with a single thread. Check out java.util.Timer, which has done most of the work for you.
Does creating a new thread each time suck up more memory and processor than a single thread which runs for the life of the application?
Probably yes. However the difference may well be too small to matter; it depends on how many tasks you're talking about, and how long they take, and what else is going on in the JVM and processor, and what's the phase of the moon... very difficult to give a solid general answer here.
How would you mesasure this?
Ideally with something like JProbe, if you / your employer can pay for it. But there's some good free tools as well. JAMon looks like a good candidate.

Do you have some working code that is executing too slowly? Are you interested in a general answer to this question? You can always
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the purpose of the spawned thread? parallel processing, or program responsivness?
 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by CL Gilbert:
What is the purpose of the spawned thread? parallel processing, or program responsivness?


The thread does some HTTP polling.
For example, downloads current stock quotes, images, news, etc. on demand.
Drew
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say keep a dedicated thread. But it does not have to be running. It should be in wait() state till its told again to fetch its data.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic