What is Multithreading?
A thread executes a series of instructions. Every line of code that is executed is done so by a thread. Some threads can run for the entire life of the applet, while others are alive for only a few milliseconds.Multithreading is the ability to have various parts of program perform program steps seemingly at the same time. Java let programs interleave multiple program steps through the use of threads. For example,one thread controls an animation, while another does a computation. In Java, multithreading is not only powerful, it is also easy to implement.
You can implement threads within a java program in two ways – Creating an object that extends Class Thread or implementing the interface Runnable.
The key difference between the two is that Thread class has a strart() method which your program simple calls whereas the Runnable class does not have a start method and you must create a Thread object and pass your thread to its constructor method. You never call run() method directly; the start method calls it for you.
Example:
Class MyProcess extends Thread{
Public void run(){
}
public static void main(String args[]){
MyProcess mp = new MyProcess();
mp.start();
}
}
Class MyProcess implements Runnable {
Public void run(){
}
public static void main(String args[]){
Thread mp = new Thread(new MyProcess());
mp.start();
}
}
FAQ Home
Sponsored links
Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
SFTP components for .NET
Add complete SSH and SFTP support to your .NET framework application
Add complete SSH and SFTP support to your .NET framework application
Virtual File System SDK
Create your own file systems in Windows and .NET applications
Create your own file systems in Windows and .NET applications
PureCM Software Configuration Management
Version control and integrated issue tracking - powerful and easy to use. Get your FREE trial now!
Version control and integrated issue tracking - powerful and easy to use. Get your FREE trial now!
