Get Some Free Products at your Door Step. Just feed ur Address in dis Link...!!

Sunday, November 27, 2011

Multiple work through multithreading...!!

import java.util.logging.Level;
import java.util.logging.Logger;

class mthreading
{
public static void main(String ar[])
{
new work1();
System.out.println("Main");
new work2();
System.out.println("Main");
new work3();
System.out.println("Main");
}
}
class work1 implements Runnable
{
Thread wt;
work1()
{
wt = new Thread(this,"Work1");
wt.start();
}
public void run()
{
System.out.println("Work one is activated");
try {
wt.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(work1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
class work2 implements Runnable
{
Thread wt2;
work2()
{
wt2 = new Thread(this,"Work2");
wt2.start();
}
public void run()
{
System.out.println("Work two is activated");
try {
wt2.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(work1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
class work3 implements Runnable
{
Thread wt3;
work3()
{
wt3 = new Thread(this,"Work3");
wt3.start();
}
public void run()
{
System.out.println("Work three is activated");
try {
wt3.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(work1.class.getName()).log(Level.SEVERE, null, ex);
}
}

}

No comments:

Post a Comment