Files
AdvanceJava/MyThread.java
2026-01-29 14:05:10 +05:30

26 lines
643 B
Java

// write a java code for two thread performing two task at a time
public class MyThread extends Thread{
String task;
MyThread(String task){
this.task = task;
}
public void run(){
synchronized(this) {
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[]){
MyThread th1 = new MyThread("Cut the ticket");
MyThread th2 = new MyThread("Show your seat number");
th1.start();
th2.start();
}
}