-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadSemaphore.java
More file actions
40 lines (34 loc) · 911 Bytes
/
ThreadSemaphore.java
File metadata and controls
40 lines (34 loc) · 911 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
35
36
37
38
39
40
import java.util.concurrent.Semaphore;
public class ThreadSemaphore extends Thread {
static Runnable runnerA = new Runnable() {
public void run () {
System.out.println("A");
}
};
static Runnable runnerB = new Runnable() {
public void run () {
System.out.println("B");
}
};
static Runnable runnerC = new Runnable() {
public void run () {
System.out.println("C");
}
};
public void run() { // override Thread's run()
System.out.println("Here is the starting point of Thread.");
for (;;) { // infinite loop to print message
System.out.println("User Created Thread");
}
}
public static void main (String[] args) {
Thread t = new ThreadSemaphore();
t.start();
Thread ta = new Thread(runnerA, "t_a");
Thread tb = new Thread(runnerB, "t_b");
Thread tc = new Thread(runnerC, "t_c");
ta.start();
tb.start();
tc.start();
}
}