public class SpecificNotification { void acquire(int t, boolean highPriority) { } void doSomething(int t){ System.out.println("Thread "+t+" has resource"); try { Thread.sleep(500); } catch (InterruptedException e) { } } void release(int t, boolean highPriority){ } /** * PROGRAM */ public static void main(String[] args) throws InterruptedException { final SpecificNotification sn = new SpecificNotification(); for(int t=0;t<4;t++){ final int T=t; new Thread(){ public void run(){ for(int i=0;i<10;i++){ sn.acquire(T, T<2); // threads 0 and 1 get priority sn.doSomething(T); sn.release(T, T<2); try { Thread.sleep(10); } catch (InterruptedException e) { } } System.out.println("Thread "+T+" FINISHES"); } }.start(); } } }