35 lines
691 B
Java
35 lines
691 B
Java
|
|
// write a java code for two threads performing two tasks at a time
|
||
|
|
public class MyThreadd extends Thread
|
||
|
|
{
|
||
|
|
String task;
|
||
|
|
|
||
|
|
MyThreadd(String task)
|
||
|
|
{
|
||
|
|
this.task = task;
|
||
|
|
}
|
||
|
|
public void run()
|
||
|
|
{
|
||
|
|
for(int i=1; i<=5; i++)
|
||
|
|
{
|
||
|
|
System.out.println(task+ ":" +i);
|
||
|
|
try{
|
||
|
|
Thread.sleep(1000);
|
||
|
|
}
|
||
|
|
catch(InterruptedException ie)
|
||
|
|
{
|
||
|
|
System.out.println(ie.getMessage());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
public static void main(String[] args)
|
||
|
|
{
|
||
|
|
MyThreadd th1 = new MyThreadd("Cut the ticket");
|
||
|
|
MyThreadd th2 = new MyThreadd("Show your seat number");
|
||
|
|
|
||
|
|
Thread t1 = new Thread(th1);
|
||
|
|
Thread t2 = new Thread(th2);
|
||
|
|
t1.start();
|
||
|
|
t2.start();
|
||
|
|
}
|
||
|
|
}
|