aspose file tools*
The moose likes Threads and Synchronization and the fly likes Starting Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Starting Threads" Watch "Starting Threads" New topic
Author

Starting Threads

Marcus Senna
Greenhorn

Joined: Feb 22, 2007
Posts: 21
How could I start running multiple threads at the same time?
M Easter
Ranch Hand

Joined: Feb 11, 2007
Posts: 133
Bruce Eckel's book "Thinking in Java" contains an intro to threads. It is available online for free (easily googled)

Mike


M Easter
Software Composer - http://codetojoy.blogspot.com
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The Sun Conurrency Tutorial is pretty good, too.

In short

0) Read the tutorial or Thinking in Java.

1) Write a class that implements the Runnable interface. Put the guts of the work to be done in the run() method, pass any data required to do the job to the constructor.

2) Do something like this:


When it comes time to get data back from the thread or make two threads interact with each other, things get trickier. The Sun tutorial will get you there. BTW: This all got much easier in Java5. If you're in an older JDK, see if you can get up to Java5.

Let us know how you make out!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Marcus Senna
Greenhorn

Joined: Feb 22, 2007
Posts: 21
Hey, What I am doing is creating an application which allows users to simulate certain communications protocols. This application would allow users to configure networks using network components such as routers and hosts by dragging and dropping images of them onto a configuration area. and then setting up links between them. I have created a thread to deal with Host objects sending data, another thread to deal with propagation delay in Link objects and another thread to deal with routing in the Router objects. I have a timer thread which allows me to vary the rate at which Host objects send data and also to allow me to simulate a propagation delay in the Link objects. The problem i am getting is that, after the Host objects have sent all the data and I return from that thread, it seems as though the other two threads are stopping also. I would like the other two threads to continue running until all the data is sent to the destination Host object. Thanks in advance for your feedback!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Starting Threads