本文整理汇总了Java中java.util.concurrent.locks.ReentrantLock.newCondition方法的典型用法代码示例。如果您正苦于以下问题:Java ReentrantLock.newCondition方法的具体用法?Java ReentrantLock.newCondition怎么用?Java ReentrantLock.newCondition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.locks.ReentrantLock
的用法示例。
在下文中一共展示了ReentrantLock.newCondition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: NIOConnection
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
NIOConnection(final short p_ownNodeId, final short p_destination, final int p_bufferSize, final int p_flowControlWindowSize,
final float p_flowControlWindowThreshold, final IncomingBufferQueue p_incomingBufferQueue, final MessageHeaderPool p_messageHeaderPool,
final MessageDirectory p_messageDirectory, final RequestMap p_requestMap, final MessageHandlers p_messageHandlers, final BufferPool p_bufferPool,
final AbstractExporterPool p_exporterPool, final NIOSelector p_nioSelector, final NodeMap p_nodeMap) {
super(p_ownNodeId);
NIOFlowControl flowControl = new NIOFlowControl(p_destination, p_flowControlWindowSize, p_flowControlWindowThreshold, p_nioSelector, this);
NIOOutgoingRingBuffer outgoingBuffer = new NIOOutgoingRingBuffer(p_bufferSize, p_exporterPool);
NIOPipeIn pipeIn =
new NIOPipeIn(p_ownNodeId, p_destination, p_messageHeaderPool, flowControl, p_messageDirectory, p_requestMap, p_messageHandlers, p_bufferPool,
p_incomingBufferQueue, this);
NIOPipeOut pipeOut = new NIOPipeOut(p_ownNodeId, p_destination, p_bufferSize, flowControl, outgoingBuffer, p_nioSelector, p_nodeMap, this);
setPipes(pipeIn, pipeOut);
m_nioSelector = p_nioSelector;
m_connectionCondLock = new ReentrantLock(false);
m_connectionCond = m_connectionCondLock.newCondition();
}
示例2: testAwaitUninterruptibly
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public void testAwaitUninterruptibly(boolean fair) {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition condition = lock.newCondition();
final CountDownLatch pleaseInterrupt = new CountDownLatch(2);
Thread t1 = newStartedThread(new CheckedRunnable() {
public void realRun() {
// Interrupt before awaitUninterruptibly
lock.lock();
pleaseInterrupt.countDown();
Thread.currentThread().interrupt();
condition.awaitUninterruptibly();
assertTrue(Thread.interrupted());
lock.unlock();
}});
Thread t2 = newStartedThread(new CheckedRunnable() {
public void realRun() {
// Interrupt during awaitUninterruptibly
lock.lock();
pleaseInterrupt.countDown();
condition.awaitUninterruptibly();
assertTrue(Thread.interrupted());
lock.unlock();
}});
await(pleaseInterrupt);
t2.interrupt();
lock.lock();
lock.unlock();
assertThreadBlocks(t1, Thread.State.WAITING);
assertThreadBlocks(t2, Thread.State.WAITING);
lock.lock();
condition.signalAll();
lock.unlock();
awaitTermination(t1);
awaitTermination(t2);
}
示例3: testHasWaitersIAE
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public void testHasWaitersIAE(boolean fair) {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition c = lock.newCondition();
final ReentrantLock lock2 = new ReentrantLock(fair);
try {
lock2.hasWaiters(c);
shouldThrow();
} catch (IllegalArgumentException success) {}
}
示例4: testSignal_IMSE
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public void testSignal_IMSE(boolean fair) {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition c = lock.newCondition();
try {
c.signal();
shouldThrow();
} catch (IllegalMonitorStateException success) {}
}
示例5: Buffer
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
* Constructor of the class. Initialize all the objects
*
* @param maxSize
* The size of the buffer
*/
public Buffer(int maxSize) {
this.maxSize = maxSize;
buffer = new LinkedList<>();
lock = new ReentrantLock();
lines = lock.newCondition();
space = lock.newCondition();
pendingLines = true;
}
开发者ID:PacktPublishing,项目名称:Java-SE-9-Road-to-Concurrent-and-High-Performance-Programming,代码行数:15,代码来源:Buffer.java
示例6: ConnectionPoolManager
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public ConnectionPoolManager(int poolSize) {
this.maxPoolSize = poolSize;
availableClients = new LinkedList<ClientWrapper>();
checkedOutClients = new HashSet<ClientWrapper>();
poolLock = new ReentrantLock();
availableClientsCondition = poolLock.newCondition();
currentPoolSize = 0;
}
示例7: prepareForFlush
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
* Internally used to indicate that the client thread will wait for this
* message to have been sent before continuing
*/
protected void prepareForFlush()
{
doneLock = new ReentrantLock();
doneCondition = doneLock.newCondition();
doneLock.lock();
}
示例8: testAwaitNanos_Timeout
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public void testAwaitNanos_Timeout(boolean fair) {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition c = lock.newCondition();
final long timeoutMillis = timeoutMillis();
final long timeoutNanos = MILLISECONDS.toNanos(timeoutMillis);
lock.lock();
final long startTime = System.nanoTime();
try {
long nanosRemaining = c.awaitNanos(timeoutNanos);
assertTrue(nanosRemaining <= 0);
} catch (InterruptedException fail) { threadUnexpectedException(fail); }
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
lock.unlock();
}
示例9: Buffer
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public Buffer(int maxSize) {
this.maxSize = maxSize;
buffer = new LinkedList<>();
lock = new ReentrantLock();
lines = lock.newCondition();
space = lock.newCondition();
pendingLines = true;
producerWaitingTimes = new AtomicInteger(0);
consumerTotalWaitingTimes = new AtomicInteger(0);
}
示例10: testGetWaitQueueLengthIMSE
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public void testGetWaitQueueLengthIMSE(boolean fair) {
final ReentrantLock lock = new ReentrantLock(fair);
final Condition c = lock.newCondition();
try {
lock.getWaitQueueLength(c);
shouldThrow();
} catch (IllegalMonitorStateException success) {}
}
示例11: SingletonValue
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public SingletonValue(SingletonBuilder<T> builder) {
this.builder = builder;
state = ValueState.NOT_SET;
sync = new ReentrantLock();
change = sync.newCondition();
}
示例12: BlockTask
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
public BlockTask() {
lock = new ReentrantLock();
condition = lock.newCondition();
//countDownLatch = new CountDownLatch(1);
}
示例13: Junction
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
Junction() {
lck = new ReentrantLock();
cnd = lck.newCondition();
}
示例14: PrimaryWriteBuffer
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
/**
* Creates an instance of PrimaryWriteBuffer with user-specific
* configuration
*
* @param p_logComponent
* the log component
* @param p_primaryLog
* Instance of the primary log. Used to write directly to primary log if buffer is full
* @param p_writeBufferSize
* the size of the write buffer
* @param p_flashPageSize
* the size of a flash page
* @param p_secondaryLogBufferSize
* the secondary log buffer size
* @param p_logSegmentSize
* the segment size
* @param p_useChecksum
* whether checksums are used
* @param p_sortBufferPooling
* whether buffer pooling is enabled or not
*/
public PrimaryWriteBuffer(final LogComponent p_logComponent, final PrimaryLog p_primaryLog, final int p_writeBufferSize, final int p_flashPageSize,
final int p_secondaryLogBufferSize, final int p_logSegmentSize, final boolean p_useChecksum, final boolean p_sortBufferPooling) {
m_logComponent = p_logComponent;
m_primaryLog = p_primaryLog;
m_writeBufferSize = p_writeBufferSize;
m_flashPageSize = p_flashPageSize;
m_secondaryLogBufferSize = p_secondaryLogBufferSize;
m_logSegmentSize = p_logSegmentSize;
m_useChecksum = p_useChecksum;
m_poolBuffers = p_sortBufferPooling;
m_bufferReadPointer = 0;
m_bufferWritePointer = 0;
m_bytesInWriteBuffer = 0;
m_timestamp = System.currentTimeMillis();
m_writerThread = null;
m_flushingComplete = false;
m_dataAvailable = false;
m_needToLock = false;
m_metadataLock = new ReentrantLock(false);
m_dataAvailableCond = m_metadataLock.newCondition();
m_finishedCopyingCond = m_metadataLock.newCondition();
if (m_writeBufferSize < m_flashPageSize || m_writeBufferSize > WRITE_BUFFER_MAX_SIZE || Integer.bitCount(m_writeBufferSize) != 1) {
throw new IllegalArgumentException("Illegal buffer size! Must be 2^x with " + Math.log(m_flashPageSize) / Math.log(2) + " <= x <= 31");
}
m_buffer = new byte[m_writeBufferSize];
m_lengthByBackupRange = new HashMap<Integer, Integer>();
m_isShuttingDown = false;
if (m_poolBuffers) {
// Creates buffers for segment pooling (2 * 8 MB, 16 * 1 MB, 32 * 0.5 MB, total: 48 MB)
m_segmentPoolLarge = new ArrayList<byte[]>();
m_segmentPoolMedium = new ArrayList<byte[]>();
m_segmentPoolSmall = new ArrayList<byte[]>();
for (int i = 0; i < 2; i++) {
m_segmentPoolLarge.add(new byte[m_logSegmentSize]);
}
for (int i = 0; i < 16; i++) {
m_segmentPoolMedium.add(new byte[m_logSegmentSize / 8]);
}
for (int i = 0; i < 32; i++) {
m_segmentPoolSmall.add(new byte[m_logSegmentSize / 16]);
}
}
m_writerThread = new PrimaryLogWriterThread();
m_writerThread.setName("Logging: Writer Thread");
m_writerThread.start();
// #if LOGGER == TRACE
LOGGER.trace("Initialized primary write buffer (%d)", m_writeBufferSize);
// #endif /* LOGGER == TRACE */
}
示例15: Task
import java.util.concurrent.locks.ReentrantLock; //导入方法依赖的package包/类
protected Task() {
lock = new ReentrantLock();
condition = lock.newCondition();
}