• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads  RSS feed

 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • 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
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not GUI Stuff related. Moving to Java in General (Intermediate)
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • 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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!