+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
43d7a64
master
1import java .util .Random ; 2import java .lang .Thread ; 3 4public class testFairUnfairBathroom implements Runnable { 5final static int SIZE =10 ; 6 7final FairUnifanBathroom bathroom ; 8final boolean ut ; 9 10public testFairUnfairBathroom (FairUnifanBathroom bathroom ,boolean ut ) { 11this .bathroom =bathroom ; 12this .ut =ut ; 13 } 14 15public void run () { 16Random rng =new Random (); 17try { 18if (ut ) { 19bathroom .enterBathroomUT (); 20 }else { 21bathroom .enterBathroomOU (); 22 } 23 24Thread .sleep (rng .nextInt (100 )); 25 26if (ut ) { 27bathroom .leaveBathroomUT (); 28 }else { 29bathroom .leaveBathroomOU (); 30 } 31 }catch (InterruptedException e ) { 32System .out .println (e ); 33 } 34 } 35 36public static void main (String []args ) { 37FairUnifanBathroom bathroom =new FairUnifanBathroom (); 38Thread []t =new Thread [SIZE ]; 39Random rng =new Random (); 40 41for (int i =0 ;i <SIZE ; ++i ) { 42t [i ] =new Thread (new testFairUnfairBathroom (bathroom ,rng .nextBoolean ())); 43 } 44 45for (int i =0 ;i <SIZE ; ++i ) { 46t [i ].start (); 47 } 48 } 49}