Java Code Examples for java.util.concurrent.locks.ReentrantLock#newCondition()
The following examples show how to use
java.util.concurrent.locks.ReentrantLock#newCondition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsumerContainerWatcherThreadTest.java From rabbitmq-cdi with MIT License | 5 votes |
@Test void testInterruptDuringRetrySleep() throws InterruptedException { ReentrantLock lock = new ReentrantLock(); Condition noConnectionCondition = lock.newCondition(); when(consumerContainerMock.isConnectionAvailable()).thenReturn(true); when(consumerContainerMock.ensureConsumersAreActive()).thenReturn(false); ConsumerContainerWatcherThread consumerContainerWatcherThread = new ConsumerContainerWatcherThread(consumerContainerMock, 1000000, lock, noConnectionCondition); consumerContainerWatcherThread.start(); Thread.sleep(350); assertTrue(consumerContainerWatcherThread.isAlive()); killThreadAndCheckState(consumerContainerWatcherThread); }
Example 2
Source File: LcdGame.java From diozero with MIT License | 5 votes |
public LcdGame(LcdConnection lcdConnection, int leftGpio, int rightGpio, int okGpio) { random = new Random(); lcd = new HD44780Lcd(lcdConnection, 20, 4); leftButton = new Button(leftGpio); rightButton = new Button(rightGpio); okButton = new Button(okGpio); lock = new ReentrantLock(); cond = lock.newCondition(); leftButton.whenReleased(this::leftReleased); rightButton.whenReleased(this::rightReleased); okButton.whenReleased(this::okReleased); }
Example 3
Source File: GifDecoder.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
public GifDecoder(GifAction gifaction) { isDestroy = false; f = 1; A = new byte[256]; B = 0; C = 0; D = 0; E = false; F = 0; O = new ArrayBlockingQueue(15); P = new ReentrantLock(); Q = P.newCondition(); R = P.newCondition(); S = 0; T = false; U = new ArrayList(M); V = 0; W = false; X = null; Y = null; Z = false; aa = 0; ab = null; ac = 0; ad = null; ae = null; af = new int[256]; X = gifaction; }
Example 4
Source File: ReentrantLockTest.java From jdk-source-analysis with Apache License 2.0 | 5 votes |
@Test public void testCondition() throws InterruptedException { ReentrantLock lock = new ReentrantLock(); Condition condition = lock.newCondition(); Thread thread = new Thread(new ConditionTask(lock, condition)); thread.start(); Thread.sleep(2000); lock.lock(); condition.signal(); lock.unlock(); }
Example 5
Source File: AbstractManualActionContext.java From JALSE with Apache License 2.0 | 5 votes |
/** * Creates a new instance of AbstractManualActionContext with the supplied engine, action and * source bindings. * * @param engine * Parent engine. * @param action * The action this context is for. * @param sourceBindings * Bindings to shallow copy. */ protected AbstractManualActionContext(final ActionEngine engine, final Action<T> action, final ActionBindings sourceBindings) { super(engine, action, sourceBindings); lock = new ReentrantLock(); ran = lock.newCondition(); done = new AtomicBoolean(); performing = new AtomicBoolean(); cancelled = new AtomicBoolean(); estimated = new AtomicLong(); unschedulable = unschedulableActionContext(this); }
Example 6
Source File: ThriftRpcClient.java From mt-flume with Apache License 2.0 | 5 votes |
public ConnectionPoolManager(int poolSize) { this.maxPoolSize = poolSize; availableClients = new LinkedList<ClientWrapper>(); checkedOutClients = new HashSet<ClientWrapper>(); poolLock = new ReentrantLock(); availableClientsCondition = poolLock.newCondition(); currentPoolSize = 0; }
Example 7
Source File: ReentrantLockTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testHasWaitersIMSE(boolean fair) { final ReentrantLock lock = new ReentrantLock(fair); final Condition c = lock.newCondition(); try { lock.hasWaiters(c); shouldThrow(); } catch (IllegalMonitorStateException success) {} }
Example 8
Source File: CallbackTask.java From jforgame with Apache License 2.0 | 5 votes |
@Override public Message call() throws Exception { try { CReqCallBack reqCallBack = (CReqCallBack) request; int index = CallBack.nextMsgId(); reqCallBack.setIndex(index); reqCallBack.serialize(); session.sendMessage(reqCallBack); ReentrantLock lock = new ReentrantLock(); Condition condition = lock.newCondition(); long maxTimeOut = 5 * TimeUtil.ONE_SECOND; long startTime = System.currentTimeMillis(); CallBackService callBackService = CallBackService.getInstance(); while (System.currentTimeMillis() - startTime <= maxTimeOut) { CallBack c = callBackService.removeCallBack(index); if (c != null) { return c.getData(); } try { lock.lockInterruptibly(); condition.await(10, TimeUnit.MILLISECONDS); } catch (Exception e) { } finally { lock.unlock(); } } } finally { C2SSessionPoolFactory.getInstance().returnSession(session); } // 超时返回 return null; }
Example 9
Source File: SingletonValue.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public SingletonValue(SingletonBuilder<T> builder) { this.builder = builder; state = ValueState.NOT_SET; sync = new ReentrantLock(); change = sync.newCondition(); }
Example 10
Source File: FirmataAdapter.java From diozero with MIT License | 5 votes |
public FirmataAdapter(FirmataEventListener eventListener) { this.eventListener = eventListener; running = new AtomicBoolean(false); responseQueue = new ConcurrentLinkedQueue<>(); lock = new ReentrantLock(); condition = lock.newCondition(); pins = new ConcurrentHashMap<>(); adcToGpioMapping = new ConcurrentHashMap<>(); executor = Executors.newSingleThreadExecutor(); }
Example 11
Source File: ReentrantLockTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void testGetWaitQueueLengthIAE(boolean fair) { final ReentrantLock lock = new ReentrantLock(fair); final Condition c = lock.newCondition(); final ReentrantLock lock2 = new ReentrantLock(fair); try { lock2.getWaitQueueLength(c); shouldThrow(); } catch (IllegalArgumentException success) {} }
Example 12
Source File: BlockingSet.java From consulo with Apache License 2.0 | 4 votes |
public BlockingSet() { set = new HashSet<T>(); lock = new ReentrantLock(); unlock = lock.newCondition(); }
Example 13
Source File: PausableThreadPoolExecutor.java From sdl_java_suite with BSD 3-Clause "New" or "Revised" License | 4 votes |
PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); threadLock = new ReentrantLock(); condition = threadLock.newCondition(); }
Example 14
Source File: StateMachineImpl.java From Camera2 with Apache License 2.0 | 4 votes |
public StateMachineImpl() { mStateLock = new ReentrantLock(); mStateChangedCondition = mStateLock.newCondition(); mState = new StateUninitialized(this); }
Example 15
Source File: BlockTask.java From Raincat with GNU Lesser General Public License v3.0 | 4 votes |
public BlockTask() { lock = new ReentrantLock(); condition = lock.newCondition(); notify = false; remove = false; }
Example 16
Source File: Task.java From lorne_core with Apache License 2.0 | 4 votes |
protected Task() { lock = new ReentrantLock(); condition = lock.newCondition(); }
Example 17
Source File: ArrayBlockingQueue.java From jdk8u60 with GNU General Public License v2.0 | 3 votes |
/** * Creates an {@code ArrayBlockingQueue} with the given (fixed) * capacity and the specified access policy. * * @param capacity the capacity of this queue * @param fair if {@code true} then queue accesses for threads blocked * on insertion or removal, are processed in FIFO order; * if {@code false} the access order is unspecified. * @throws IllegalArgumentException if {@code capacity < 1} */ public ArrayBlockingQueue(int capacity, boolean fair) { if (capacity <= 0) throw new IllegalArgumentException(); this.items = new Object[capacity]; lock = new ReentrantLock(fair); notEmpty = lock.newCondition(); notFull = lock.newCondition(); }
Example 18
Source File: WifiSearcher.java From Android with Apache License 2.0 | 3 votes |
public WifiSearcher( Context context, SearchWifiListener listener ) { mContext = context; mSearchWifiListener = listener; mLock = new ReentrantLock(); mCondition = mLock.newCondition(); mWifiManager=(WifiManager)mContext.getSystemService(Context.WIFI_SERVICE); mWifiReceiver = new WiFiScanReceiver(); }
Example 19
Source File: LinkedBlockingDeque.java From database with GNU General Public License v2.0 | 3 votes |
/** * Creates a {@code LinkedBlockingDeque} with the given (fixed) capacity and * the caller's {@link ReentrantLock} object. * <p> * <strong>Caution:</strong> By using the caller's lock, this constructor * allows the caller to break the encapsulation of the synchronization and * lock-based notification (signals). This can be used advantageously to * create designs where an outer lock is shared by the collection which * avoid deadlock arising from blocking operations on an inner lock while * holding a distinct outer lock. However, the caller's decisions about its * lock are no longer independent of the design decisions within this class * since they share the same lock. * * @param capacity * the capacity of this deque * @param lock * the lock object. * @throws IllegalArgumentException * if {@code capacity} is less than 1 */ public LinkedBlockingDeque(final int capacity, final ReentrantLock lock) { if (capacity <= 0) throw new IllegalArgumentException(); if (lock == null) throw new NullPointerException(); this.capacity = capacity; this.lock = lock; this.notEmpty = lock.newCondition(); this.notFull = lock.newCondition(); }
Example 20
Source File: ArrayBlockingQueue.java From j2objc with Apache License 2.0 | 3 votes |
/** * Creates an {@code ArrayBlockingQueue} with the given (fixed) * capacity and the specified access policy. * * @param capacity the capacity of this queue * @param fair if {@code true} then queue accesses for threads blocked * on insertion or removal, are processed in FIFO order; * if {@code false} the access order is unspecified. * @throws IllegalArgumentException if {@code capacity < 1} */ public ArrayBlockingQueue(int capacity, boolean fair) { if (capacity <= 0) throw new IllegalArgumentException(); this.items = new Object[capacity]; lock = new ReentrantLock(fair); notEmpty = lock.newCondition(); notFull = lock.newCondition(); }