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 Need help with thread pool issue.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Need help with thread pool issue.." Watch "Need help with thread pool issue.." New topic
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: 18124
    
    8

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: 291

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with thread pool issue..
 
Similar Threads
Sending an image on network..
SocketHandler / BufferedReader question
Socket is not receiving the first request after long Ideal time
Networking question
RMI Server problem