-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicThread.java
More file actions
40 lines (35 loc) · 1 KB
/
basicThread.java
File metadata and controls
40 lines (35 loc) · 1 KB
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
35
36
37
38
39
40
class RunThread implements Runnable{
private Thread thread;
private String threadName;
RunThread(String name){
threadName = name;
System.out.println("Creating " + threadName);
}
public void run(){
System.out.println("Running " + threadName);
try{
for(int iterate = 3; iterate > 0; iterate--){
System.out.println(threadName + ", " + iterate);
Thread.sleep(30);
}
} catch(InterruptedException e){
System.out.println(threadName + " interrupted.");
}
System.out.println(threadName + " exiting.");
}
public void start(){
System.out.println("Starting " + threadName );
if(thread == null){
thread = new Thread(this, threadName);
thread.start();
}
}
}
public class basicThread{
public static void main(String args[]){
RunThread R1 = new RunThread("Thread_1");
R1.start();
RunThread R2 = new RunThread("Thread_2");
R2.start();
}
}