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


Java Buffer.addAll方法代码示例

本文整理汇总了Java中org.apache.commons.collections15.Buffer.addAll方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.addAll方法的具体用法?Java Buffer.addAll怎么用?Java Buffer.addAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.collections15.Buffer的用法示例。


在下文中一共展示了Buffer.addAll方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBlockedGetWithAddAll

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll()} using multiple read threads.
 * <p/>
 * Two read threads should block on an empty buffer until a
 * singleton is added then both threads should complete.
 */
public void testBlockedGetWithAddAll() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    
    // run methods will get and compare -- must wait for addAll
    Thread thread1 = new ReadThread(blockingBuffer, obj);
    Thread thread2 = new ReadThread(blockingBuffer, obj);
    thread1.start();
    thread2.start();
    
    // give hungry read threads ample time to hang
    delay();
       
    // notifyAll should allow both read threads to complete
    blockingBuffer.addAll(Collections.singleton(obj));
           
    // allow notified threads to complete 
    delay();
    
    // There should not be any threads waiting.
    if (thread1.isAlive() || thread2.isAlive())
        fail("Live thread(s) when both should be dead.");
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:31,代码来源:TestBlockingBuffer.java

示例2: testBlockedRemoveWithAddAll1

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
/**
 * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll()} using multiple read threads.
 * <p/>
 * Two read threads should block on an empty buffer until a
 * singleton collection is added then one thread should
 * complete. The remaining thread should complete after the
 * addition of a second singleton.
 */
public void testBlockedRemoveWithAddAll1() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj = new Object();
    
    // run methods will remove and compare -- must wait for addAll
    Thread thread1 = new ReadThread(blockingBuffer, obj, null, "remove");
    Thread thread2 = new ReadThread(blockingBuffer, obj, null, "remove");
    thread1.start();
    thread2.start();
    
    // give hungry read threads ample time to hang
    delay();

    blockingBuffer.addAll(Collections.singleton(obj));
    
    // allow notified threads to complete 
    delay();
    
    // There should be one thread waiting.
    assertTrue("There is one thread waiting", thread1.isAlive() ^ thread2.isAlive());

    blockingBuffer.addAll(Collections.singleton(obj));
    
    // allow notified thread to complete 
    delay();

    // There should not be any threads waiting.
    if (thread1.isAlive() || thread2.isAlive())
        fail("Live thread(s) when both should be dead.");
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:40,代码来源:TestBlockingBuffer.java

示例3: testBlockedRemoveWithAddAll2

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
/**
 * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#addAll()} using multiple read threads.
 * <p/>
 * Two read threads should block on an empty buffer until a
 * collection with two distinct objects is added then both
 * threads should complete. Each thread should have read a
 * different object.
 */
public void testBlockedRemoveWithAddAll2() {

    Buffer blockingBuffer = BlockingBuffer.decorate(new MyBuffer());
    Object obj1 = new Object();
    Object obj2 = new Object();

    Set objs = Collections.synchronizedSet(new HashSet());
    objs.add(obj1);
    objs.add(obj2);

    // run methods will remove and compare -- must wait for addAll
    Thread thread1 = new ReadThread(blockingBuffer, objs, "remove");
    Thread thread2 = new ReadThread(blockingBuffer, objs, "remove");
    thread1.start();
    thread2.start();
    
    // give hungry read threads ample time to hang
    delay();

    blockingBuffer.addAll(objs);
    
    // allow notified threads to complete 
    delay();

    assertEquals("Both objects were removed", 0, objs.size());

    // There should not be any threads waiting.
    if (thread1.isAlive() || thread2.isAlive())
        fail("Live thread(s) when both should be dead.");
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:39,代码来源:TestBlockingBuffer.java

示例4: makeFullCollection

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
public Collection makeFullCollection() {
    Buffer buffer = new UnboundedFifoBuffer();
    buffer.addAll(Arrays.asList(getFullElements()));
    return UnmodifiableBuffer.decorate(buffer);
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:6,代码来源:TestUnmodifiableBuffer.java

示例5: makeFullCollection

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
public Collection makeFullCollection() {
    Buffer buffer = new UnboundedFifoBuffer();
    buffer.addAll(Arrays.asList(getFullElements()));
    return SynchronizedBuffer.decorate(buffer);
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:6,代码来源:TestSynchronizedBuffer.java


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