-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiThread2.java
More file actions
42 lines (36 loc) · 1.01 KB
/
MultiThread2.java
File metadata and controls
42 lines (36 loc) · 1.01 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
class withdrawThread extends Thread{
static int totalBalance=1000;
int amount;
withdrawThread(int amount){
this.amount=amount;
}
public void run(){
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 MultiThread2{
public static void main(String[] args) {
withdrawThread obj = new withdrawThread(800);
withdrawThread obj2 = new withdrawThread(300);
obj.start();
try{
obj.join();
} catch(InterruptedException e) {
e.printStackTrace();
}
obj2.start();
}
}