first commit
This commit is contained in:
25
MyThread.java
Normal file
25
MyThread.java
Normal file
@@ -0,0 +1,25 @@
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user