当前位置: 首页>>代码示例>>Java>>正文


Java BlockingQueue.put方法代码示例

本文整理汇总了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();
            }
        }
    }
}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:25,代码来源:RejectedPolicy.java

示例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
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:SmokeTest.java

示例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);
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:21,代码来源:MessagingController.java

示例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;
    }
  }
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:27,代码来源:TestDataSetUtilsVolume.java

示例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;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:19,代码来源:MultiNodeSelectHandler.java

示例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();
            }
        }
    }
}
 
开发者ID:yu199195,项目名称:myth,代码行数:25,代码来源:RejectedPolicy.java

示例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;
}
 
开发者ID:KodeMunkie,项目名称:imagetozxspec,代码行数:38,代码来源:HumbleVideoImportEngine.java

示例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;
    }
  }
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:25,代码来源:TestDataSetUtilsVolume.java

示例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());
    }
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:21,代码来源:ArrayBlockingQueueExample.java

示例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();
        }
    }
}
 
开发者ID:brucezee,项目名称:jspider,代码行数:12,代码来源:WebDriverPool.java

示例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
        }
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:28,代码来源:MultiNodeMergeHandler.java

示例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);
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:12,代码来源:MultiNodeSelectHandler.java

示例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);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:8,代码来源:PersoonCacheProducer.java

示例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);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:12,代码来源:PersoonCacheProducer.java

示例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);
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:12,代码来源:PersoonsBeeldenServiceImpl.java


注:本文中的java.util.concurrent.BlockingQueue.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。