-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQue-39.java
More file actions
32 lines (28 loc) · 960 Bytes
/
Copy pathQue-39.java
File metadata and controls
32 lines (28 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//Write a program which create two threads and then generates numbers from 15 to 1 for the delay of 1sec between them. Display the thread details for the current thread and changed thread name to thread1 to “San” and thread2 to “Bag”.
//By: Parth Panjwani
class myThread extends Thread {
public void run() {
synchronized (myThread.class){
System.out.println( "\n" + this.getName() );
for( int i=15; i>=0; i-- ){
System.out.print(i + " ");
try{
this.sleep(1000);
}
catch(Exception e){
System.out.println("ERROR");
}
}
}
};
}
public class Main9 {
public static void main(String[] args) {
myThread t1 = new myThread();
myThread t2 = new myThread();
t1.setName("San");
t2.setName("Bag");
t1.start();
t2.start();
}
}