public abstract class Mutex { public static void criticalSection() { try { Thread.sleep((int) (Math.random() * 3000)); } catch (InterruptedException e) { // Nothing } } public static void nonCriticalSection() { try { Thread.sleep((int) (Math.random() * 3000)); } catch (InterruptedException e) { // Nothing } } // Take ownership public abstract void p(int id); // Release ownership public abstract void v(int id); }