This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
Joined: Apr 18, 2002
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!
Joined: Jul 15, 2003
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.
Joined: Apr 18, 2002
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?