forked from Kotlin-Polytech/FromKotlinToJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
40 lines (36 loc) · 1.04 KB
/
Copy pathClient.java
File metadata and controls
40 lines (36 loc) · 1.04 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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package part4.deposit.sync;
import part4.deposit.naive.Deposit;
/**
*
* @author Eugene Pychkine
*/
@SuppressWarnings("WeakerAccess")
public class Client extends Thread {
private final Deposit deposit;
private final int change;
Client( Deposit deposit, int change ) {
super( "Bank client" );
this.deposit = deposit;
this.change = change;
}
@Override
public void run() {
try {
synchronized(deposit) {
int balance = deposit.getBalance();
System.out.println( "Client: balance before transaction: " +
balance );
balance += change;
deposit.setBalance(balance);
System.out.println( "Client: balance: " + balance );
}
}
catch( InterruptedException e ) {
System.out.println( "Interrupting client thread");
}
}
}