-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.java
More file actions
30 lines (27 loc) · 842 Bytes
/
Copy pathUser.java
File metadata and controls
30 lines (27 loc) · 842 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
package com.java4j.lock.testsynchronized;
import java.util.concurrent.TimeUnit;
/**
* 测试用户类
*
* @author java4j
*/
public class User {
public synchronized void serviceA() {
System.out.println(Thread.currentThread().getName() + " Begin serviceA.");
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + " End serviceA.");
}
public void serviceB() {
System.out.println(Thread.currentThread().getName() + " Begin serviceB.");
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + " End serviceB.");
}
}