class BookTheaterSeat {
int total_seats = 10;
//synchronized method
synchronized void bookSeat(int seats) {
if (total_seats >= seats) {
System.out.println(seats + " Seats booked Successfully");
total_seats -= seats;
System.out.println("Total seats available= " + total_seats);
} else {
System.out.println("Booking failed less seat are available");
System.out.println("Seats available are : " + total_seats);
}
}
}
public class MovieBookApp extends Thread {
int seats;
static BookTheaterSeat b;
@Override
public void run() {
b.bookSeat(seats);
}
public static void main(String[] args) {
b = new BookTheaterSeat();
MovieBookApp mb1 = new MovieBookApp();
mb1.seats = 3;
mb1.start();
MovieBookApp mb2 = new MovieBookApp();
mb2.seats = 6;
mb2.start();
}
}