• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Starting Threads

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How could I start running multiple threads at the same time?
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bruce Eckel's book "Thinking in Java" contains an intro to threads. It is available online for free (easily googled)

Mike
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Marcus Senna
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic