It's allow sample
Semaphore sem = new Semaphore(1); //allow only 1 member . Log.d("test", "constructure"); sem.drainPermits(); // No permit. Log.d("test", "drainPermits"); sem.release(); //release semaphore and 1 permit. Log.d("test", "release"); try { sem.acquire(); //require permit. } catch (InterruptedException e) { e.printStackTrace(); } Log.d("test", "acquire"); //allowedUp program log:
constructure drainPermits release acquireup program source code
Other allow sample.
Semaphore sem = new Semaphore(1); //allow only 1 member . Log.d("test", "constructure. and first time, 1 member permit"); try { sem.acquire(); //require permit. } catch (InterruptedException e) { e.printStackTrace(); } Log.d("test", "acquire. and now 0 member permit."); //allowed try { sem.acquire(); //require permit. } catch (InterruptedException e) { e.printStackTrace(); } Log.d("test", "May not reach"); //allowedUp program log:
constructure. and first time, 1 member permit acquire. and now 0 member permit.up program source code
reject sample.
Semaphore sem = new Semaphore(1); //allow only 1 member . Log.d("test", "constructure"); sem.drainPermits(); // No permit. Log.d("test", "drainPermits"); Log.d("test", "May be reject to acquire"); try { sem.acquire(); //require permit. } catch (InterruptedException e) { e.printStackTrace(); } Log.d("test", "May not reach"); //allowedUp program log:
constructure drainPermits May be reject to acquireup program source code
0 件のコメント:
コメントを投稿