This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Raveendran Karunakaran
Ranch Hand

Joined: Jun 25, 2001
Posts: 38

Can anybody teach me as in the simplest of ways as to how i can use threads in my applications ?
rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
A thread, called as a lightweight process, is a single sequential flow of control within a program. You use threads to isolate tasks. The JVM allows an application to have multiple threads of execution running concurrently. Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority.
There are two ways to create a new thread of execution.
One is to declare a class to be a subclass of Thread. This subclass should override the run method of class Thread. An instance of the subclass can then be allocated and started.
For e.g., a thread that does some computation

The following code would then create a thread and start it running:


The other way to create a thread is to declare a class that implements the Runnable interface thus implementing the run() method. An instance of the class can then be allocated, passed as an argument when creating Thread, and started.
For e.g.

The following code would then create a thread and start it running:


Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads