| Author |
Thread Management
|
Ben Klug
Ranch Hand
Joined: Jan 28, 2002
Posts: 45
|
|
Hi, I need an idea! I've got a servlet, each time it is requested a thread starts in an other class. The trouble is, that this causes performance-problems. I need to reduce the threads to a maximum of three. If someone requests the servlet and there are allready three threads running, the fourth thread should wait, until on of the three running threads has finished. I hope you can understand what I need. Thanks in advance for any tipp! Ben
|
 |
William Barnes
Ranch Hand
Joined: Mar 16, 2001
Posts: 949
|
|
|
Well the class you are in creates the other threads. So you should know how many you have. Set up a counter and keep track of them.
|
Please ignore post, I have no idea what I am talking about.
|
 |
Ben Klug
Ranch Hand
Joined: Jan 28, 2002
Posts: 45
|
|
Hi Willam, thanks for your reply, but I don't get it. where can I set up the counter? I've got three classes: 1. Servlet 2. ThreadManager 3. Thread The Servlet calls the Thread manager in the ThreadManager class, I start the Thread itself like this: But each time, the Servlet calls an new instance of ThreadManager, so I can start many Threads. I need to access the existing Instance in some way.. any Ideas??? thanks! Ben I think I'm al little  [ April 22, 2003: Message edited by: Ben Klug ]
|
 |
William Barnes
Ranch Hand
Joined: Mar 16, 2001
Posts: 949
|
|
|
Have an array which only holds 3 threads. Look in the array for a free thread, and use that one. Else wait.
|
 |
William Barnes
Ranch Hand
Joined: Mar 16, 2001
Posts: 949
|
|
Actually I think I am answering your question as if this was non-servlet code. Each request that comes in gets it own Servlet code, I think. There is a Servlet forum on which people should be able to give you better answers than I can. But, ...
I've got a servlet, each time it is requested a thread starts in an other class. The trouble is, that this causes performance-problems.
I can't believe that making less threads is going to solve your performance problems. If you have more than 3 requests, but are only able to service 3 at a time the clients may timeout waiting to get serviced. Maybe you should consider limiting the number of requests you can process at any given time, at the web server layer. That way clients will get a bad http status really quick, instead of timing out. Usally I just ramble on until someone who knows what the hell they are talking about shows up. Hopefully that will happen again.
|
 |
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
|
|
|
Moving to the Threads forum.
|
"JavaRanch, where the deer and the Certified play" - David O'Meara
|
 |
 |
|
|
subject: Thread Management
|
|
|