| Author |
Need help with thread pool issue..
|
Sam Smoot
Ranch Hand
Joined: Apr 18, 2002
Posts: 238
|
|
First, I will admit up front that this is a homework assignment. I need some guideance, but I am not looking for a final solution. However, I have no other resource at this time to eyeball this with me to see what is missing, so any good nudge will be greatly appreciated. I have a class DateServer that is supposed to generate multiple threads (5) for a client to access. This is what I have, but... I then have a client (DateClient) that is currently only a single thread, but I also have to modify it to create 50 threads to act like there are multiple request accessing the DateServer. Originally, I had a loop around the try block for 50 passes, and it worked on the original server, but only 1 at a time. Again, I'm not looking for the direct solution, but a good hint in the right direction is greatly appreciated.
|
CNSS/NSA Infosec Professional,<br />Software Engineer
|
 |
Ken Blair
Ranch Hand
Joined: Jul 15, 2003
Posts: 1078
|
|
|
Move everything in your main method to a Runnable. Then, in a loop, create a new Thread using that Runnable and start the Thread. Each iteration of the loop will create a new Thread that executes that code and your current Thread will return immediately.
|
 |
Sam Smoot
Ranch Hand
Joined: Apr 18, 2002
Posts: 238
|
|
I'm assuming you are talking about the client part. I'm gonna give it a try and see if it'll work (probably will, I'm really too old for this...) Thanks for the help! Sam
|
 |
Ken Blair
Ranch Hand
Joined: Jul 15, 2003
Posts: 1078
|
|
|
Yes. You're attempting to simulate a bunch of concurrent connections right? If you just put it in a loop then it all gets executed sequentially. If instead you move the code to a Runnable and create a loop that makes a bunch of new Threads it will execute more or less concurrently, which sounds like what you want.
|
 |
Sam Smoot
Ranch Hand
Joined: Apr 18, 2002
Posts: 238
|
|
Well, it kinda works, but now the server won't reuse the threads.... How do you make the server recycle the threads on it's end? ================= [ March 09, 2006: Message edited by: Sam Smoot ]
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
Generally you don't make the server reuse the threads, you just create a new thread whenever the server needs one. Why are you trying to reuse threads?
|
 |
Edward Harned
Ranch Hand
Joined: Sep 19, 2005
Posts: 288
|
|
You�re using the services of pre-written code (Executors, ExecutorService). This relieves the programmer of low-level coding and frees him/her to tackle problem solving. Live with it, or do it yourself. If you want to manage a pool of threads, then you�re in for a lot of work. That�s the kind of stuff I like, but then I don�t have a homework assignment to do.
|
Ed's latest article: A Java Parallel Calamity http://coopsoft.com/ar/Calamity2Article.html
|
 |
 |
|
|
subject: Need help with thread pool issue..
|
|
|