本文整理汇总了Java中java.util.concurrent.BlockingQueue.put方法的典型用法代码示例。如果您正苦于以下问题:Java BlockingQueue.put方法的具体用法?Java BlockingQueue.put怎么用?Java BlockingQueue.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.BlockingQueue
的用法示例。
在下文中一共展示了BlockingQueue.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rejectedExecution
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
if (threadName != null) {
LOG.error("tccTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
}
if (runnable instanceof RejectedRunnable) {
((RejectedRunnable) runnable).rejected();
} else {
if (!executor.isShutdown()) {
BlockingQueue<Runnable> queue = executor.getQueue();
int discardSize = queue.size() >> 1;
for (int i = 0; i < discardSize; i++) {
queue.poll();
}
try {
queue.put(runnable);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
示例2: putQ
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
static void putQ(BlockingQueue<String> q, String o) {
try {
q.put(o);
} catch (InterruptedException e) {
// can't happen
}
}
示例3: putCommand
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private void putCommand(BlockingQueue<Command> queue, String description, MessagingListener listener,
Runnable runnable, boolean isForeground) {
int retries = 10;
Exception e = null;
while (retries-- > 0) {
try {
Command command = new Command();
command.listener = listener;
command.runnable = runnable;
command.description = description;
command.isForegroundPriority = isForeground;
queue.put(command);
return;
} catch (InterruptedException ie) {
SystemClock.sleep(200);
e = ie;
}
}
throw new Error(e);
}
示例4: produceWithHintedColumnCounts
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private void produceWithHintedColumnCounts(BlockingQueue<Iterable<Record>> queue, Function<RecordBuilder, Record> randomizer) {
Thread.currentThread().setName("Producer-" + Thread.currentThread().getId());
outer: while (true) {
ArrayList<Record> batch = new ArrayList<>();
for (int j = 0 ; j < BATCH_SIZE ; j++) {
batch.add(
RecordDecorator.of(
RecordDecorator.of(randomizer.apply(record().withInitialColumnCount(9)))
.withInitialColumnCount(2)
.setString("XXX", "werwer")
.setString("YYY", "dfsgsf"))
.withInitialColumnCount(1)
.setString("ZZZ", "sdfsdfs")
);
if (Thread.currentThread().isInterrupted()) {
break outer;
}
}
try {
queue.put(batch);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break outer;
}
}
}
示例5: rowResponse
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
@Override
public boolean rowResponse(final byte[] row, RowDataPacket rowPacketNull, boolean isLeft, BackendConnection conn) {
if (errorResponse.get() || noNeedRows) {
return true;
}
BlockingQueue<HeapItem> queue = queues.get(conn);
if (queue == null)
return true;
RowDataPacket rp = new RowDataPacket(fieldCount);
rp.read(row);
HeapItem item = new HeapItem(row, rp, (MySQLConnection) conn);
try {
queue.put(item);
} catch (InterruptedException e) {
LOGGER.info("rowResponse error", e);
}
return false;
}
示例6: rejectedExecution
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
if (threadName != null) {
LOG.error("MythTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
}
if (runnable instanceof RejectedRunnable) {
((RejectedRunnable) runnable).rejected();
} else {
if (!executor.isShutdown()) {
BlockingQueue<Runnable> queue = executor.getQueue();
int discardSize = queue.size() >> 1;
for (int i = 0; i < discardSize; i++) {
queue.poll();
}
try {
queue.put(runnable);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
示例7: snapshotImageIfAtSampleTime
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
/**
* Snapshots an image to the sharedQueue if at the requested time interval
*
* @param picture from which to get the timestamp
* @param systemTimeBase the time base for this system
* @param streamStartTime the start time for the stream
* @param streamTimeBase the stream time base
* @param nextSnapShotTime the time at which the snapshot is expected
* @param sharedQueue the shared processing queue
* @param converter the media converter for making the snampshot
* @param sampleRateNanos the sampling rate for the video in nanoseconds
* @return the next snapshot time (current snapshot time + sampleRateNanos)
* @throws InterruptedException if the snapshot cannot be added to the shared queue
*/
private Long snapshotImageIfAtSampleTime(MediaPicture picture, Rational systemTimeBase, long streamStartTime, Rational streamTimeBase, Long nextSnapShotTime,
BlockingQueue<Image> sharedQueue, MediaPictureConverter converter, long sampleRateNanos) throws InterruptedException {
if (picture.isComplete()) {
long streamTimestamp = picture.getTimeStamp();
// Convert streamTimestamp into system units (i.e. nano-seconds)
streamTimestamp = systemTimeBase.rescale(streamTimestamp-streamStartTime, streamTimeBase);
if (nextSnapShotTime == null || streamTimestamp >= nextSnapShotTime) {
BufferedImage image = converter.toImage(null, picture);
boolean added = sharedQueue.offer(image);
if (!added && !cancel) {
log.debug("Video queue full at {}... blocking", streamTimestamp);
sharedQueue.put(image);
} else {
log.debug("Video queue had space");
}
nextSnapShotTime = streamTimestamp+sampleRateNanos;
log.debug("Timestamp {}, Next snapshot {}", streamTimestamp, nextSnapShotTime);
}
}
return nextSnapShotTime;
}
示例8: produce
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private void produce(BlockingQueue<Iterable<Record>> queue, Function<RecordBuilder, Record> randomizer) {
Thread.currentThread().setName("Producer-" + Thread.currentThread().getId());
outer: while (true) {
ArrayList<Record> batch = new ArrayList<>();
for (int j = 0 ; j < BATCH_SIZE ; j++) {
batch.add(
RecordDecorator.of(
RecordDecorator.of(
randomizer.apply(record())
).setString("XXX", "werwer").setString("YYY", "dfsgsf")
).setString("ZZZ", "sdfsdfs")
);
if (Thread.currentThread().isInterrupted()) {
break outer;
}
}
try {
queue.put(batch);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break outer;
}
}
}
示例9: main
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {
BlockingQueue<String> queue = new ArrayBlockingQueue<>(1);
queue.add("add");
//
String peek = queue.peek();
System.out.println(peek);
queue.poll();
boolean offer = queue.offer("offer");
if (!offer) {
System.out.println("it is't possible to do so immediately");
}
System.out.println(queue.take());
queue.put("put operation");
System.out.println(queue.take());
}
示例10: returnWebDriver
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
public void returnWebDriver(WebDriverEx webDriver, Request request) {
DriverType driverType = chooser.choose(request);
BlockingQueue<WebDriverEx> queue = queueMap.get(driverType);
if (queue != null) {
try {
queue.put(webDriver);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
示例11: rowEofResponse
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
@Override
public void rowEofResponse(byte[] data, boolean isLeft, BackendConnection conn) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(conn.toString() + " 's rowEof is reached.");
}
((MySQLConnection) conn).setRunning(false);
if (this.terminate.get())
return;
if (isEasyMerge) {
lock.lock();
try {
if (++reachedConCount == route.length)
nextHandler.rowEofResponse(null, this.isLeft, conn);
} finally {
lock.unlock();
}
} else {
BlockingQueue<HeapItem> queue = queues.get(conn);
if (queue == null)
return;
try {
queue.put(HeapItem.nullItem());
} catch (InterruptedException e) {
//ignore error
}
}
}
示例12: rowEofResponse
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
@Override
public void rowEofResponse(final byte[] eof, boolean isLeft, BackendConnection conn) {
BlockingQueue<HeapItem> queue = queues.get(conn);
if (queue == null)
return;
try {
queue.put(HeapItem.nullItem());
} catch (InterruptedException e) {
LOGGER.info("rowEofResponse error", e);
}
}
示例13: poisonTaken
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private void poisonTaken(BlockingQueue<PersoonCacheBatchOpdracht> taakQueue) throws InterruptedException {
for (int i = 0; i < configuratieService.getPoolSizeBlobBatchProducer(); i++) {
final PersoonCacheBatchOpdracht taak = new PersoonCacheBatchOpdracht();
taak.setStop(true);
taakQueue.put(taak);
}
}
示例14: zetOpdrachtenOpQueue
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private void zetOpdrachtenOpQueue(BlockingQueue<PersoonCacheBatchOpdracht> taakQueue, MinMaxPersoonCacheDTO minMaxPersoonCacheDTO)
throws InterruptedException {
final boolean stop = selectieJobRunStatusService.getStatus().moetStoppen();
for (long i = minMaxPersoonCacheDTO.getMinId(); i < minMaxPersoonCacheDTO.getMaxId() + 1 && !stop;
i = i + configuratieService.getBatchSizeBatchProducer()) {
final PersoonCacheBatchOpdracht taak = new PersoonCacheBatchOpdracht();
taak.setMinIdPersoonCache(i);
taak.setMaxIdPersoonCache(i + configuratieService.getBatchSizeBatchProducer());
taakQueue.put(taak);
}
}
示例15: zetOpdrachtenOpQueue
import java.util.concurrent.BlockingQueue; //导入方法依赖的package包/类
private void zetOpdrachtenOpQueue(SelectieVerwerkTaakBericht selectieTaak, int verwerkerPoolSize,
BlockingQueue<MaakPersoonslijstBatchOpdracht> persoonsBeeldTaakQueue)
throws InterruptedException {
//zet de opdrachten op de queue
final List<List<SelectiePersoonBericht>> bundelChunks = Lists.partition(selectieTaak.getPersonen(), verwerkerPoolSize);
for (List<SelectiePersoonBericht> bundelChunk : bundelChunks) {
final MaakPersoonslijstBatchOpdracht maakPersoonslijstBatchOpdracht = new MaakPersoonslijstBatchOpdracht();
maakPersoonslijstBatchOpdracht.setCaches(bundelChunk);
persoonsBeeldTaakQueue.put(maakPersoonslijstBatchOpdracht);
}
}