本文整理匯總了Java中java.util.concurrent.LinkedBlockingQueue.add方法的典型用法代碼示例。如果您正苦於以下問題:Java LinkedBlockingQueue.add方法的具體用法?Java LinkedBlockingQueue.add怎麽用?Java LinkedBlockingQueue.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.concurrent.LinkedBlockingQueue
的用法示例。
在下文中一共展示了LinkedBlockingQueue.add方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testIteratorRemove
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
/**
* iterator.remove removes current element
*/
public void testIteratorRemove() {
final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
q.add(two);
q.add(one);
q.add(three);
Iterator it = q.iterator();
it.next();
it.remove();
it = q.iterator();
assertSame(it.next(), one);
assertSame(it.next(), three);
assertFalse(it.hasNext());
}
示例2: testOfferInExecutor
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
/**
* offer transfers elements across Executor tasks
*/
public void testOfferInExecutor() {
final LinkedBlockingQueue q = new LinkedBlockingQueue(2);
q.add(one);
q.add(two);
final CheckedBarrier threadsStarted = new CheckedBarrier(2);
final ExecutorService executor = Executors.newFixedThreadPool(2);
try (PoolCleaner cleaner = cleaner(executor)) {
executor.execute(new CheckedRunnable() {
public void realRun() throws InterruptedException {
assertFalse(q.offer(three));
threadsStarted.await();
assertTrue(q.offer(three, LONG_DELAY_MS, MILLISECONDS));
assertEquals(0, q.remainingCapacity());
}});
executor.execute(new CheckedRunnable() {
public void realRun() throws InterruptedException {
threadsStarted.await();
assertSame(one, q.take());
}});
}
}
示例3: testDrainTo
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
/**
* drainTo(c) empties queue into another collection c
*/
public void testDrainTo() {
LinkedBlockingQueue q = populatedQueue(SIZE);
ArrayList l = new ArrayList();
q.drainTo(l);
assertEquals(0, q.size());
assertEquals(SIZE, l.size());
for (int i = 0; i < SIZE; ++i)
assertEquals(l.get(i), new Integer(i));
q.add(zero);
q.add(one);
assertFalse(q.isEmpty());
assertTrue(q.contains(zero));
assertTrue(q.contains(one));
l.clear();
q.drainTo(l);
assertEquals(0, q.size());
assertEquals(2, l.size());
for (int i = 0; i < 2; ++i)
assertEquals(l.get(i), new Integer(i));
}
示例4: parseM3u8
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
private void parseM3u8(String m3u8Url, String newM3u8FileName, String outputPath, LinkedBlockingQueue<Map<String, String>> sizeDetectQueue, LinkedBlockingQueue<Map<String, String>> downloadQueue) throws IOException {
String m3U8Content = HttpRequestUtil.getResponseString(HttpRequestUtil.sendGetRequest(m3u8Url));
String newM3u8FileContent = "";
boolean subFile = false;
for(String lineStr:m3U8Content.split("\n")){
if(lineStr.startsWith("#")){
newM3u8FileContent = newM3u8FileContent+lineStr+"\n";
if(lineStr.startsWith("#EXT-X-STREAM-INF")){
subFile = true;
}
}else{
String uuidStr = UUIDUtil.genUUID();
String fileUrl = new URL(new URL(m3u8Url), lineStr.trim()).toString();
if(subFile){
subFile = false;
parseM3u8(fileUrl, uuidStr+".m3u8", outputPath,sizeDetectQueue, downloadQueue);
newM3u8FileContent = newM3u8FileContent+"/"+uuidStr + ".m3u8\n";
}else{
String videoFilePath = outputPath + File.separator + uuidStr + ".ts";
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("url", fileUrl);
hashMap.put("downloadPath", videoFilePath);
sizeDetectQueue.add(hashMap);
downloadQueue.add(hashMap);
newM3u8FileContent = newM3u8FileContent+"/"+ uuidStr + ".ts\n";
}
}
}
FileUtil.stringToFile(newM3u8FileContent, outputPath+File.separator+newM3u8FileName);
}
示例5: test_queue_copy
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
@Test
public void test_queue_copy() {
LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<String>();
queue.add("abc");
LinkedBlockingQueue<String> queueMileage = new LinkedBlockingQueue<String>(queue);
// String trucknum = queueMileage.poll();
queueMileage.remove();
// System.out.println(trucknum);
System.out.println(queue);
}
示例6: testEmptyFull
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
/**
* Queue transitions from empty to full when elements added
*/
public void testEmptyFull() {
LinkedBlockingQueue q = new LinkedBlockingQueue(2);
assertTrue(q.isEmpty());
assertEquals("should have room for 2", 2, q.remainingCapacity());
q.add(one);
assertFalse(q.isEmpty());
q.add(two);
assertFalse(q.isEmpty());
assertEquals(0, q.remainingCapacity());
assertFalse(q.offer(three));
}
示例7: testAdd
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
/**
* add succeeds if not full; throws IllegalStateException if full
*/
public void testAdd() {
LinkedBlockingQueue q = new LinkedBlockingQueue(SIZE);
for (int i = 0; i < SIZE; ++i)
assertTrue(q.add(new Integer(i)));
assertEquals(0, q.remainingCapacity());
try {
q.add(new Integer(SIZE));
shouldThrow();
} catch (IllegalStateException success) {}
}
示例8: testClear
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
/**
* clear removes all elements
*/
public void testClear() {
LinkedBlockingQueue q = populatedQueue(SIZE);
q.clear();
assertTrue(q.isEmpty());
assertEquals(0, q.size());
assertEquals(SIZE, q.remainingCapacity());
q.add(one);
assertFalse(q.isEmpty());
assertTrue(q.contains(one));
q.clear();
assertTrue(q.isEmpty());
}
示例9: testContainsAll
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
/**
* containsAll(c) is true when c contains a subset of elements
*/
public void testContainsAll() {
LinkedBlockingQueue q = populatedQueue(SIZE);
LinkedBlockingQueue p = new LinkedBlockingQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.containsAll(p));
assertFalse(p.containsAll(q));
p.add(new Integer(i));
}
assertTrue(p.containsAll(q));
}
示例10: testIteratorOrdering
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
/**
* iterator ordering is FIFO
*/
public void testIteratorOrdering() {
final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
q.add(one);
q.add(two);
q.add(three);
assertEquals(0, q.remainingCapacity());
int k = 0;
for (Iterator it = q.iterator(); it.hasNext();) {
assertEquals(++k, it.next());
}
assertEquals(3, k);
}
示例11: testWeaklyConsistentIteration
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
/**
* Modifications do not cause iterators to fail
*/
public void testWeaklyConsistentIteration() {
final LinkedBlockingQueue q = new LinkedBlockingQueue(3);
q.add(one);
q.add(two);
q.add(three);
for (Iterator it = q.iterator(); it.hasNext();) {
q.remove();
it.next();
}
assertEquals(0, q.size());
}
示例12: insertData
import java.util.concurrent.LinkedBlockingQueue; //導入方法依賴的package包/類
private LinkedBlockingQueue<Long> insertData() throws IOException, InterruptedException {
LinkedBlockingQueue<Long> rowKeys = new LinkedBlockingQueue<Long>(25000);
BufferedMutator ht = util.getConnection().getBufferedMutator(this.tableName);
byte[] value = new byte[300];
for (int x = 0; x < 5000; x++) {
TraceScope traceScope = Trace.startSpan("insertData", Sampler.ALWAYS);
try {
for (int i = 0; i < 5; i++) {
long rk = random.nextLong();
rowKeys.add(rk);
Put p = new Put(Bytes.toBytes(rk));
for (int y = 0; y < 10; y++) {
random.nextBytes(value);
p.add(familyName, Bytes.toBytes(random.nextLong()), value);
}
ht.mutate(p);
}
if ((x % 1000) == 0) {
admin.flush(tableName);
}
} finally {
traceScope.close();
}
}
admin.flush(tableName);
return rowKeys;
}