-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultithread3.java
More file actions
49 lines (39 loc) · 1.16 KB
/
Multithread3.java
File metadata and controls
49 lines (39 loc) · 1.16 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
41
42
43
44
45
46
47
48
49
class withdrawThread extends Thread{
static int totalBalance=1000;
int amount;
withdrawThread(int amount){
this.amount=amount;
}
public void run(){
synchronized(withdrawThread.class){
if(totalBalance>=amount){
System.out.println("paisa aapke pass aa jayega" +amount);
try{
Thread.sleep(1000);
}catch (InterruptedException e){
//TODO Auto-generated catch block
e.printStackTrace();
}
totalBalance-=amount;
System.out.println(totalBalance);
}
else{
System.out.println("Limit ma raho");
}
}
}
}
public class Multithread3{
public static void main(String[] args) {
withdrawThread obj = new withdrawThread(800);
withdrawThread obj2 = new withdrawThread(300);
obj.start();
try {
obj.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
obj2.start();
}
}