Package java.util.concurrent.locks

Examples of java.util.concurrent.locks.ReentrantLock


    else {
      configureOptimizerStrategy(searchFactoryImplementor, indexProps, provider);
      configureIndexingParameters(searchFactoryImplementor, indexProps, provider);
      providers.add( provider );
      if ( !searchFactoryImplementor.getLockableDirectoryProviders().containsKey( provider ) ) {
        searchFactoryImplementor.getLockableDirectoryProviders().put( provider, new ReentrantLock() );
      }
      return provider;
    }
  }
View Full Code Here


public class LockDelegate implements ILock {

    private final Lock delegate;
   
    public LockDelegate() {
        this.delegate = new ReentrantLock(true);
    }
View Full Code Here

        }
    }

    public static class NoCleanUpRemoteProcess implements Action<WorkerProcessContext>, Serializable {
        public void execute(WorkerProcessContext workerProcessContext) {
            final Lock lock = new ReentrantLock();
            lock.lock();
            new Thread(new Runnable() {
                public void run() {
                    lock.lock();
                }
            }).start();

            TestListenerInterface sender = workerProcessContext.getServerConnection().addOutgoing(
                    TestListenerInterface.class);
View Full Code Here

            }
        });
        current = new HashMap<String, SourceSequence>();
       
        retransmissionQueue = new RetransmissionQueue(h, getRMAssertion());        
        sequenceCreationLock = new ReentrantLock();
        sequenceCreationCondition = sequenceCreationLock.newCondition();
    }
View Full Code Here

    public void testSchedule() throws Exception {
        workqueue = new AutomaticWorkQueueImpl(UNBOUNDED_MAX_QUEUE_SIZE, INITIAL_SIZE,
                                               UNBOUNDED_HIGH_WATER_MARK,
                                               UNBOUNDED_LOW_WATER_MARK,
                                               DEFAULT_DEQUEUE_TIMEOUT);
        final Lock runLock = new ReentrantLock();
        final Condition runCondition = runLock.newCondition();
        long start = System.currentTimeMillis();
        Runnable doNothing = new Runnable() {
            public void run() {
                runLock.lock();
                try {
                    runCondition.signal();
                } finally {
                    runLock.unlock();
                }
            }
        };
       
        workqueue.schedule(doNothing, 5000);
       
        runLock.lock();
        try {
            runCondition.await();
        } finally {
            runLock.unlock();
        }
       
        assertTrue("expected delay",
                   System.currentTimeMillis() - start >= 4950);
    }
View Full Code Here

    }

    public void setUp() throws BusException {
        bus = EasyMock.createMock(Bus.class);
        wsdlManager = new WSDLManagerImpl(null);
        partialResponseReceivedLock = new ReentrantLock();
        partialResponseReceivedCondition = partialResponseReceivedLock.newCondition();
        partialResponseReceivedNotified = false;
        responseCallback = new TestResponseCallback();
        clientBinding = EasyMock.createMock(ClientBinding.class);
    }
View Full Code Here

  @SuppressWarnings("unused")
  private void asyncSetState(final Collection<INews> news, final State state, final boolean affectEquivalentNews, final boolean force) throws PersistenceException {
    if (news.isEmpty())
      return;
    final NewsEventRunnable eventRunnable = new NewsEventRunnable();;
    final Lock setStateLock = new ReentrantLock();
    setStateLock.lock();
    final Condition condition = setStateLock.newCondition();
    fExecutorService.execute(new Runnable() {
      public void run() {
        Set<INews> changedNews = null;
        try {
          fWriteLock.lock();
          setStateLock.lock();

          if (affectEquivalentNews) {
            /*
             * Give extra 25% size to take into account news that have same guid or
             * link.
             */
            int capacity = news.size() + (news.size() / 4);
            changedNews = new HashSet<INews>(capacity);
            for (INews newsItem : news) {
              if (newsItem.getId() == null)
                throw new IllegalArgumentException("newsItem was never saved to the database"); //$NON-NLS-1$

              List<INews> equivalentNews;

              if (newsItem.getGuid() != null) {
                equivalentNews = getNewsFromGuid(newsItem, true);
                if (equivalentNews.isEmpty()) {
                  throw createIllegalException("No news were found with guid: " + //$NON-NLS-1$
                      newsItem.getGuid().getValue(), newsItem);
                }
              } else if (newsItem.getLinkAsText() != null) {
                equivalentNews = getNewsFromLink(newsItem, true);
                if (equivalentNews.isEmpty()) {
                  throw createIllegalException("No news were found with link: " + //$NON-NLS-1$
                      newsItem.getLinkAsText(), newsItem);
                }
              } else
                equivalentNews = Collections.singletonList(newsItem);

              changedNews.addAll(setState(equivalentNews, state, force));
            }
          } else {
            changedNews = setState(news, state, force);
          }
          for (INews changedNewsItem : changedNews) {
            //TODO Investigate why we add the news twice to the event runnable
            //(we do the same in the finally block). This is harmless but
            //wasteful. Also we should not release the news locks before firing
            //the events.
            ((News) changedNewsItem).acquireReadLockSpecial();
            eventRunnable.addCheckedUpdateEvent(createSaveEventTemplate(changedNewsItem));
          }
          condition.signal();
          setStateLock.unlock();
          save(changedNews);
          fDb.commit();
        } catch (Db4oException e) {
          throw new PersistenceException(e);
        } finally {
          if (changedNews != null) {
            for (INews changedNewsItem : changedNews) {
              ((News) changedNewsItem).releaseReadLockSpecial();
              eventRunnable.addCheckedUpdateEvent(createSaveEventTemplate(changedNewsItem));
            }
          }
          DBHelper.cleanUpEvents();
          fWriteLock.unlock();
        }
      }
    });
    try {
      condition.awaitUninterruptibly();
    } finally {
      setStateLock.unlock();
    }
    eventRunnable.run();
  }
View Full Code Here

   *
   * @param fair whether this monitor should use a fair ordering policy rather than a non-fair (but
   *        fast) one
   */
  public Monitor(boolean fair) {
    this.lock = new ReentrantLock(fair);
  }
View Full Code Here

   * Enters this monitor. Blocks at most the given time.
   *
   * @return whether the monitor was entered
   */
  public boolean enter(long time, TimeUnit unit) {
    final ReentrantLock lock = this.lock;
    long startNanos = System.nanoTime();
    long timeoutNanos = unit.toNanos(time);
    long remainingNanos = timeoutNanos;
    boolean interruptIgnored = false;
    try {
      while (true) {
        try {
          return lock.tryLock(remainingNanos, TimeUnit.NANOSECONDS);
        } catch (InterruptedException ignored) {
          interruptIgnored = true;
          remainingNanos = (timeoutNanos - (System.nanoTime() - startNanos));
        }
      }
View Full Code Here

   */
  public void enterWhen(Guard guard) throws InterruptedException {
    if (guard.monitor != this) {
      throw new IllegalMonitorStateException();
    }
    final ReentrantLock lock = this.lock;
    boolean reentrant = lock.isHeldByCurrentThread();
    lock.lockInterruptibly();
    try {
      waitInterruptibly(guard, reentrant);
    } catch (Throwable throwable) {
      lock.unlock();
      throw Throwables.propagate(throwable);
    }
  }
View Full Code Here

TOP

Related Classes of java.util.concurrent.locks.ReentrantLock

Copyright © 2018 www.massapicom. 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.