-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
33 lines (33 loc) · 843 Bytes
/
Account.java
File metadata and controls
33 lines (33 loc) · 843 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
public class Account {
public int balanceAmount;
public Account(){
balanceAmount= 10000;
}
public synchronized void withdraw(int amount)throws InterruptedException{
Thread.sleep(1000);
balanceAmount = balanceAmount - amount;
System.out.println(balanceAmount);
}
}
class Mythread extends Thread{
Account obj = null;
Mythread (Account tobj){
obj = tobj;
}
public void run(){
try {
obj.withdraw(500);
} catch (InterruptedException e) {
System.out.println(e);
}
}
}
class Test{
public static void main(String[] args) {
Account a = new Account();
Mythread ob1 = new Mythread(a);
Mythread ob2 = new Mythread(a);
ob1.start();
ob2.start();
}
}