publicclass Resource...{ publicstaticboolean inUse; //public boolean inUse=false; String name; int sleepTime=0; publicsynchronizedvoid out(String n)...{ this.name=n; while(Resource.inUse==true) try...{ System.out.println("Name:"+getName()+" Waiting..."); this.wait(); }catch(InterruptedException ie)...{ ie.printStackTrace(); } Resource.inUse=true; // entry the block and lock it try...{ sleepTime=(int)(Math.random()*5000); System.out.println("Name:"+getName()+" in use; define Sleep Time: "+sleepTime+",wait 50000 to exit the synchronize block"); Thread.sleep(5000); System.out.println("Name:"+getName()+" end 5000 sleep . Sleep some time after notify to test if others can end first"); Thread.sleep(5000-sleepTime); System.out.println("Name:"+getName()+" will Exit the synchronize block"); Resource.inUse=false; System.out.println("Name:"+getName()+" End. "+Resource.inUse); this.notifyAll(); }catch(InterruptedException ie)...{ ie.printStackTrace(); } } public String getName()...{ return name; } }