import java.rmi.*; import java.rmi.server.*; //// Distributed mutex implementation // Every remote call to a method on a RemoteObject will spin off a new // thread, which may need to be synchronized. The distributed concurrency // is thus mirrored by local thread-concurrency on the server. public class dmuteximpl extends UnicastRemoteObject implements dmutex { boolean lock = false; String name; // even default constructor must throw RemoteException public dmuteximpl() throws RemoteException {} public synchronized void lock() { try { if (lock) wait(); lock = true; } catch (InterruptedException ie) {System.out.println(ie);} } // lock public synchronized void unlock() { lock = false; notify(); } public boolean getState() { return lock; } // main method to initiate RMI engine: public static void main(String[] args) throws Exception { dmuteximpl server = new dmuteximpl(); Naming.rebind("dmutex0",server); // register with rmiregistry }//main } //dmuteximpl