-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiThreading6.java
More file actions
50 lines (36 loc) · 1014 Bytes
/
MultiThreading6.java
File metadata and controls
50 lines (36 loc) · 1014 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
41
42
43
44
45
46
47
48
49
50
public class MultiThreading6 {
public static class MyThread implements Runnable{
Thread t;
long click=0;
private volatile boolean running=true;
@Override
public void run() {
while(running){
click++;
}
}
MyThread(){
t=new Thread(this);
}
}
public static void main(String[] args){
MyThread t1=new MyThread();
MyThread t2=new MyThread();
t1.t.setPriority(Thread.NORM_PRIORITY);
t2.t.setPriority(Thread.NORM_PRIORITY);
t1.t.start();
t2.t.start();
try{
Thread.sleep(1000);
}catch (Exception e){
}
t1.running=false;
t2.running=false;
try {
t1.t.join();
t2.t.join();
}catch (Exception e){
}
System.out.println(String.format("t1 - %d\nt2 - %d", t1.click, t2.click));
}
}