forked from brianway/java-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun14_setNewStringTwoLock.java
More file actions
53 lines (44 loc) · 968 Bytes
/
Copy pathRun14_setNewStringTwoLock.java
File metadata and controls
53 lines (44 loc) · 968 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
51
52
53
package com.brianway.learning.java.multithread.synchronize.example14;
/**
* Created by Brian on 2016/4/13.
*/
/**
* P114
* 锁对象改变
*/
public class Run14_setNewStringTwoLock {
public static void main(String[] args) throws InterruptedException {
final Service service = new Service();
Thread a = new Thread() {
@Override
public void run() {
service.testMethod();
}
};
a.setName("A");
Thread b = new Thread() {
@Override
public void run() {
service.testMethod();
}
};
b.setName("B");
a.start();
Thread.sleep(50);
b.start();
}
}
/*
输出:
A begin 1460536381652
B begin 1460536381702
A end 1460536383652
B end 1460536383702
--------------
//Thread.sleep(50);
输出:
A begin 1460536503287
A end 1460536505287
B begin 1460536505287
B end 1460536507287
*/