當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。