Package java.util.concurrent

Examples of java.util.concurrent.Semaphore.availablePermits()


            server.stop();

            // test background retry
            client.checkExists().inBackground().forPath("/hey");
            Assert.assertTrue(semaphore.tryAcquire(MAX_RETRIES, timing.forWaiting().seconds(), TimeUnit.SECONDS), "Remaining leases: " + semaphore.availablePermits());
        }
        finally
        {
            CloseableUtils.closeQuietly(client);
        }
View Full Code Here


                                try
                                {
                                    if ( isFirst.compareAndSet(true, false) )
                                    {
                                        semaphore.release(THREAD_QTY - 1);
                                        while ( semaphore.availablePermits() > 0 )
                                        {
                                            Thread.sleep(100);
                                        }
                                    }
                                    else
View Full Code Here

              factoryBean.close();
            }

            batchContext.close();

            if(semaphore.availablePermits() == 0) {
              semaphore.release();
            }
          }
        }
      });
View Full Code Here

              factoryBean.close();
            }

            batchContext.close();

            if(semaphore.availablePermits() == 0) {
              semaphore.release();
            }
          }
        }
      });
View Full Code Here

        // 2 should become the leader
        elector1.shutdown();
        assertTrue(sem2.tryAcquire(5, TimeUnit.SECONDS));
        assertTrue(elector2.isLeader());
        assertEquals(0, sem3.availablePermits());

        // 3 should become the leader now
        elector2.shutdown();
        assertTrue(sem3.tryAcquire(5, TimeUnit.SECONDS));
        assertTrue(elector3.isLeader());
View Full Code Here

        // 3 should become the leader now
        elector1.shutdown();
        assertTrue(sem3.tryAcquire(5, TimeUnit.SECONDS));
        assertTrue(elector3.isLeader());
        assertEquals(0, sem3.availablePermits());

        elector3.shutdown();
    }

    @Test
View Full Code Here

     * @param ratio ratio of permits in total permits for this type. 0 <= ratio <= 1.
     */
    public Semaphore addType(int type, double ratio) {
        Semaphore permits = new Semaphore((int) (m_totalPermits * ratio));
        m_permits.put(type, permits);
        m_initialPermits.put(type, permits.availablePermits());
        return permits;
    }

    public void resetPermits() {
        for (Entry<Integer, Semaphore> e : m_permits.entrySet()) {
View Full Code Here

                async.run();
            }
        });

        // drain checkpoint permits
        checkpoint.acquireUninterruptibly(checkpoint.availablePermits());
        // block NodeStore.retrieve()
        retrieve.acquireUninterruptibly();
        t.start();

        // wait until async update called checkpoint
View Full Code Here

                thread.join(60 * 1000);
                if (thread.isAlive())
                    throw new Error
                        (String.format
                         ("Semaphore stuck: permits %d, thread waiting %s%n",
                          sem.availablePermits(),
                          sem.hasQueuedThreads() ? "true" : "false"));
            }
            if (badness[0] != null)
                throw new Error(badness[0]);
            if (sem.availablePermits() != 0)
View Full Code Here

                          sem.availablePermits(),
                          sem.hasQueuedThreads() ? "true" : "false"));
            }
            if (badness[0] != null)
                throw new Error(badness[0]);
            if (sem.availablePermits() != 0)
              throw new Error(String.valueOf(sem.availablePermits()));
            if (sem.hasQueuedThreads())
              throw new Error(String.valueOf(sem.hasQueuedThreads()));
            if (sem.getQueueLength() != 0)
              throw new Error(String.valueOf(sem.getQueueLength()));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.