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
Joined: Feb 22, 2007
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!!