How to control threads
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jiyong_chen
Posted On:   Monday, December 10, 2001 08:23 PM


I need an example of how to control threads: say 15 requests coming in, the program can only handle 5 at a time, so it checks if it can still handle a thread, if there are more than 5, it stores the rest of requests in a queue... Appreciate your help.


Please use html tags to format code blocks.

Re: How to control threads

Posted By:   Alex_Chaffee  
Posted On:   Saturday, December 15, 2001 08:30 AM

What you want is called a "thread pool". There is already a FAQ about that: How can I create a pool of threads for use in my program?

Re: How to control threads

Posted By:   Edward_Harned  
Posted On:   Tuesday, December 11, 2001 09:24 AM

Read my article at:



http://www-106.ibm.com/developerworks/java/library/j-rmiframe/



Although it is about RMI, you can easily remove the front-end RMI code and use it as an
embedded server.

Re: How to control threads

Posted By:   Bozidar_Dangubic  
Posted On:   Tuesday, December 11, 2001 06:45 AM

create a pool of thread workers that are serving your clients. when requests start to come in, try to get a worker thread from the pool. if there are any available threads, give it the request and let it fulfill it. if there are no threads available, block the incoming thread and wait until one becomes available. by managing your thread pool of workers you can later increase/decrease the size of the pool, and do many other nice things. there are thread pool stuff out there on the web so if you do a search I am sure you will be able to find the implementation that you can reuse.
About | Sitemap | Contact