• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with thread pool issue..

 
Sam Smoot
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic