-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreads.java
More file actions
34 lines (18 loc) · 806 Bytes
/
Threads.java
File metadata and controls
34 lines (18 loc) · 806 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
33
34
package threads;
public class Threads extends Thread {
private final int threadNumber;
//This is constructor of the thread class which takes thread number as argument and assigns it to the threadNumber variable. This will help us to identify which thread is running when we print the thread number in the run method.
public Threads(int threadNumber) {
this.threadNumber = threadNumber;
}
@Override
public void run() {
System.out.printf("\nThread No. %d is Starting %n", this.threadNumber);
try{
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
System.out.printf("\nThread %d is completed %n", this.threadNumber, this.getState());
}
}