File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Thread Management Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Thread Management" Watch "Thread Management" New topic
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
 
IntelliJ Java IDE
 
subject: Thread Management
 
Threads others viewed
Thread doubt
jsf thread batch processing how to
listing 11.5 on manning book ( setting on isthreadSafe)
Thread Management
thread problem
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture