• 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

Threads

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I have a question about threads. Consider the below program



As you can see above i have three methods in the above class. My question is how do i call each of these methods in a separate thread either in the class main or in the class itself

Consider the below method



As you can see from the above method i have two command lines in the above method. My question is how do i call each command line in a separate thread.

Basically i need to know how to call a specific method or a specific command line in a separate thread excluding the main thread

I hope someone can help me with both these questions

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not GUI Stuff related. Moving to Java in General (Intermediate)
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically, you define each of your threads as a separate subclass of Thread (using "extends Thread"). Within these classes, you override the run() method to include whatever you want that thread to do.

Then in your main program, you create instances of these different thread objects, and call start() on them. This will make that thread eligible to execute as its own thread -- per platform-dependent scheduling -- and will automatically invoke the run() method. If you call run() directly, then the method will execute in the current thread rather than as its own thread.

See the "Threads" topic in The Java Tutorial...
http://java.sun.com/docs/books/tutorial/essential/threads/index.html

Or the "Concurrency" chapter in Bruce Eckel's Thinking in Java...
http://www.faqs.org/docs/think_java/TIJ315.htm
[ February 07, 2005: Message edited by: marc weber ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic