-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.java
More file actions
29 lines (29 loc) · 804 Bytes
/
Customer.java
File metadata and controls
29 lines (29 loc) · 804 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
class Bus implements Runnable{
int available=1,passenger;
Bus(int passenger){
this.passenger=passenger;
}
public synchronized void run(){
String name =Thread.currentThread().getName();
if(available>=passenger){
System.out.println(name+"reserved");
available=available-passenger;
} else{
System.out.println("Not reserved");
}
}
}
public class Customer {
public static void main(String[] args){
Bus r = new Bus(1);
Thread t1 = new Thread(r);
Thread t2 = new Thread(r);
Thread t3 = new Thread(r);
t1.setName("Ram");
t2.setName("Raju");
t3.setName("Ravi");
t1.start();
t2.start();
t3.start();
}
}