dcsimg
Creating threads repeatedly
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Shan_Thiruvarur
Posted On:   Friday, September 11, 2009 06:00 PM

Gents I have this situation There is an event triggered every 5 minutes When that event is triggered, i create a thread & that does some job In the above scenario, one new thread is created every 5 minutes. At the 10th minute, what happens to the resources that are used by the thread that was created at the 5th minute? I am just trying to assume what will happen if a thread consumes significant amount of resources to complete a task while threads are created repeatedly. Is this an overhead of resources ? Will i run out of memory ?    More>>

Gents




I have this situation


There is an event triggered every 5 minutes

When that event is triggered, i create a thread & that does some job





In the above scenario, one new thread is created every 5 minutes.





At the 10th minute, what happens to the resources that are used by the thread that was created at the 5th minute?





I am just trying to assume what will happen if a thread consumes significant amount of resources to complete a task while threads are created repeatedly.





Is this an overhead of resources ? Will i run out of memory ?

   <<Less

Re: Creating threads repeatedly

Posted By:   Edward_Harned  
Posted On:   Saturday, September 12, 2009 02:50 PM

When you exit the run() method the thread will be destroyed and eventually the resources will be freed. Exactly when that happens naturally depends on a lot of issues.


Usually the better way, when using many threads, is to re-use the threads that finish the work. This is where a Queue and thread pool come into use. While there is a thread pool class in java, using such is not for beginners.


We could talk all day on how to do this and just what the problems are but it might be easier to read an article I wrote last spring and you can download an open source product that might fit your needs. ( http://coopsoft.com/ar/j2searticle.html )

About | Sitemap | Contact