Input
Output
class Interruptingthread{ public static void main(String args[]) { Customer cus = new Customer(); new Consumer(cus); new Producer(cus); } } class Customer { int Stock=1000; synchronized void get(int Stock) { if(this.Stock<Stock){ System.out.println("Less Stock and Customer waiting for refill"); try { wait(); } catch(InterruptedException e) { System.out.println("InterruptedException caught"); } this.Stock-=Stock; System.out.println("Stock Soldout Sucessfully"); } } synchronized void put(int Stock) { System.out.println("Going for Stock refill"); this.Stock+=Stock; System.out.println("Stock refill is completed "); notify(); } } class Producer implements Runnable { Customer cus; Producer(Customer cus) { this.cus = cus; new Thread(this, "Producer").start(); } public void run() { cus.put(2000); } } class Consumer implements Runnable { Customer cus; Consumer(Customer cus) { this.cus = cus; new Thread(this, "Consumer").start(); } public void run() { while(true) { cus.get(1500); } } }