-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearialNumGen.java
More file actions
55 lines (42 loc) · 1.35 KB
/
Copy pathSearialNumGen.java
File metadata and controls
55 lines (42 loc) · 1.35 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ConcurrentProcess;
/*产生不同的序列号*/
public class SearialNumGen {
private static /*volatile */ long searialNum;
private static synchronized long getSearialNum(){
return searialNum++;
}
public static void startThread(){
/* Thread threadA=new Thread(new Runnable() {
@Override
public void run() {
System.out.println("A:"+ getSearialNum()+" "+System.currentTimeMillis());
}
});
Thread threadB=new Thread(new Runnable() {
@Override
public void run() {
System.out.println("B:"+ getSearialNum()+" "+System.currentTimeMillis());
}
});
Thread threadC=new Thread(new Runnable() {
@Override
public void run() {
System.out.println("C:"+ getSearialNum()+" "+System.currentTimeMillis());
}
});
threadA.start();
threadB.start();
threadC.start();*/
for(int i=0;i<10000;i++){
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("B:"+ getSearialNum()+" "+System.currentTimeMillis());
}
}).start();
}
}
public static void main(String[] args) {
startThread();
}
}