-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankMain.java
More file actions
29 lines (23 loc) · 983 Bytes
/
Copy pathBankMain.java
File metadata and controls
29 lines (23 loc) · 983 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
package thread.sync;
import static util.MyLogger.log;
import static util.ThreadUtils.sleep;
public class BankMain {
public static void main(String[] args) throws InterruptedException {
// final BankAccountV1 account = new BankAccountV1(1000);
// final BankAccountV2 account = new BankAccountV2(1000);
// BankAccountV3 account = new BankAccountV3(1000);
// BankAccountV4 account = new BankAccountV4(1000);
// BankAccountV5 account = new BankAccountV5(1000);
BankAccountV6 account = new BankAccountV6(1000);
Thread t1 = new Thread(new WithdrawTask(account, 800), "t1");
Thread t2 = new Thread(new WithdrawTask(account, 800), "t2");
t1.start();
t2.start();
sleep(500); // 검증 완료까지 잠시 대기
log("t1 state: " + t1.getState());
log("t2 state: " + t2.getState());
t1.join();
t2.join();
log("최종 잔액: " + account.getBalance());
}
}