Lock newCondition - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Lock newCondition method.

This code example shows how to use the following methods:lock, newCondition, unlock
        Init, Stopped
    } 
 
    private static final int MAX_QUEUE_SIZE = 200;
    private final Lock lock = new ReentrantLock();
    private final Condition condition = lock.newCondition();
    private final LinkedList<T> queue = new LinkedList<T>();
    private final Executor executor;
    private final int maxQueueSize;
    private int dispatchers;
    private State state;
 
    public AsyncDispatch(Executor executor) {
        this(executor, null, MAX_QUEUE_SIZE);
    } 
 
    public AsyncDispatch(Executor executor, final Dispatch<? super T> dispatch) {
        this(executor, dispatch, MAX_QUEUE_SIZE);
    } 
 

7
CodeRank
This code example shows how to use the following methods:newCondition
  } 
 
  private static class TestListener implements ZKPersistentConnection.EventListener 
  { 
    private final Lock _lock = new ReentrantLock();
    private final Condition _stateChanged = _lock.newCondition();
 
    private ZKPersistentConnection.Event _state; 
    private long _count = 0;
 
    @Override 
    public void notifyEvent(ZKPersistentConnection.Event event) 
    { 
      _lock.lock();
      try 
      { 
        _state = event; 
        _count++;
        _stateChanged.signalAll();
      } 
6
CodeRank
This code example shows how to use the following methods:newCondition
/** 
 * Queues messages until a receiver has been connected. This class is thread-safe. 
 */ 
public class QueuingDispatch<T> implements Dispatch<T>, Stoppable {
    private final Lock lock = new ReentrantLock();
    private final Condition condition = lock.newCondition();
    private List<T> queue = new ArrayList<T>();
    private Dispatch<? super T> dispatch;
 
    /** 
     * Dispatches to the given handler. The handler does not have to be thread-safe. 
     */ 
    public void dispatchTo(Dispatch<? super T> dispatch) {
        lock.lock();
        try { 
            this.dispatch = dispatch;
            for (T message : queue) {
                dispatch.dispatch(message);
            } 
            queue = null;
6
CodeRank
This code example shows how to use the following methods:newCondition
public class SimpleHttpResponseHandler extends SimpleChannelUpstreamHandler 
{ 
  private byte[] _receivedBytes = null;
  private HttpResponse _response = null;
  private Lock _lock = new ReentrantLock();
  private Condition _hasResponseCondition = _lock.newCondition();
  private boolean _hasResponse = false;
 
  @Override 
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
  { 
    _response = (HttpResponse) e.getMessage();
    ChannelBuffer content = _response.getContent();
    _receivedBytes = new byte[content.readableBytes()];
    content.getBytes(0, _receivedBytes);
    _lock.lock();
    try 
    { 
      _hasResponse = true;
      _hasResponseCondition.signalAll();
6
CodeRank
This code example shows how to use the following methods:newCondition
    private final Distribution distribution;
    private final ToolingImplementationLoader implementationLoader;
    private final LoggingProvider loggingProvider;
 
    private final Lock lock = new ReentrantLock();
    private final Condition condition = lock.newCondition();
    private final Set<Thread> executing = new HashSet<Thread>();
    private boolean stopped;
    private ConsumerConnection connection;
 
    private final ConnectionParameters connectionParameters;
 
    public LazyConsumerActionExecutor(Distribution distribution, ToolingImplementationLoader implementationLoader, LoggingProvider loggingProvider, ConnectionParameters connectionParameters) {
        this.distribution = distribution;
        this.implementationLoader = implementationLoader;
        this.loggingProvider = loggingProvider;
        this.connectionParameters = connectionParameters;
    } 
 
    public void stop() { 
6
CodeRank
This code example shows how to use the following methods:newCondition
  } 
 
  private static class MockBusSink implements PropertyEventBus<String>
  { 
    private final Lock _lock = new ReentrantLock();
    private final Condition _initCondition = _lock.newCondition();
    private final Condition _addCondition = _lock.newCondition();
    private final Condition _removeCondition = _lock.newCondition();
 
    private Map<String,String> _currentValues = new HashMap<String, String>();
 
    public void awaitInit(String key, String value, long timeout, TimeUnit timeoutUnit)
            throws InterruptedException, TimeoutException 
    { 
      Date deadline = new Date(System.currentTimeMillis() + timeoutUnit.toMillis(timeout));
      _lock.lock();
      try 
      { 
        while (!compare(_currentValues.get(key), value))
        { 
6
CodeRank
This code example shows how to use the following methods:newCondition
public class SimpleObjectCaptureHandler extends SimpleChannelUpstreamHandler 
{ 
 
  private final List<Object> _messages;
  private final Lock _msgLock = new ReentrantLock();
  private final Condition _newMsgCondition = _msgLock.newCondition();
 
  public SimpleObjectCaptureHandler() 
  { 
    _messages = new Vector<Object>();
  } 
 
  public void clear() 
  { 
    _msgLock.lock();
    try 
    { 
      _messages.clear();
    } 
    finally 
6
CodeRank
This code example shows how to use the following methods:lock, newCondition, unlock
    */ 
    public static LeaderElector instance() 
    { 
        if ( instance_ == null )
        { 
            LeaderElector.createLock_.lock();
            try 
            { 
                if ( instance_ == null )
                { 
                    instance_ = new LeaderElector();
                } 
            } 
            finally 
            { 
                createLock_.unlock();
            } 
        } 
        return instance_;
    } 

6
CodeRank
This code example shows how to use the following methods:newCondition
public class ServiceLifecycle implements AsyncStoppable { 
    private enum State {RUNNING, STOPPING, STOPPED}
 
    private final String displayName;
    private final Lock lock = new ReentrantLock();
    private final Condition condition = lock.newCondition();
    private State state = State.RUNNING;
    private Map<Thread, Integer> usages = new HashMap<Thread, Integer>();
 
    public ServiceLifecycle(String displayName) {
        this.displayName = displayName;
    } 
 
    public void use(Runnable runnable) {
        use(Factories.toFactory(runnable));
    } 
 
    public <T> T use(Factory<T> factory) {
        lock.lock();
        try { 
6
CodeRank
This code example shows how to use the following methods:newCondition
 *  
 */ 
class FetchRequestQueue { 
    private final LinkedList<FetchRequest> queue = new LinkedList<FetchRequest>();
    private final Lock lock = new ReentrantLock();
    private final Condition available = this.lock.newCondition();
 
    /** 
     * Thread designated to wait for the element at the head of the queue. This 
     * variant of the Leader-Follower pattern 
     * (http://www.cs.wustl.edu/~schmidt/POSA/POSA2/) serves to minimize 
     * unnecessary timed waiting. When a thread becomes the leader, it waits 
     * only for the next delay to elapse, but other threads await indefinitely. 
     * The leader thread must signal some other thread before returning from 
     * take() or poll(...), unless some other thread becomes leader in the 
     * interim. Whenever the head of the queue is replaced with an element with 
     * an earlier expiration time, the leader field is invalidated by being 
     * reset to null, and some waiting thread, but not necessarily the current 
     * leader, is signalled. So waiting threads must be prepared to acquire and 
     * lose leadership while waiting. 
6
CodeRank

Related Lock newCondition Questions & Answers:

newCondition Method Overview
Returns a new Condition instance that is bound to this Lock instance.
See Code Examples for other Java 8 Lock Methods: