Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Management  RSS feed

 
Ben Klug
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1048
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Klug
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1048
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1048
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Threads forum.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!