Java 8 ConcurrentLinkedQueue - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ConcurrentLinkedQueue class.

This code example shows how to use the following methods:
 
    public static <T> Queue<T> newQueue() {
        if (useLinkedTransferQueue) {
            return new LinkedTransferQueue<>();
        } 
        return new ConcurrentLinkedQueue<>();
    } 
 
    public static <T> Deque<T> newDeque() {
        return new ConcurrentLinkedDeque<>();
    } 
 
    public static <T> BlockingQueue<T> newBlockingQueue() {
        return new LinkedTransferQueue<>();
    } 
 
    private ConcurrentCollections() { 
 
    } 
} 
9
CodeRank
This code example shows how to use the following methods:
 
    public static <T> Queue<T> newQueue() {
        if (useLinkedTransferQueue) {
            return new LinkedTransferQueue<T>(); 
        } 
        return new ConcurrentLinkedQueue<T>();
    } 
 
    public static <T> BlockingQueue<T> newBlockingQueue() {
        return new LinkedTransferQueue<T>(); 
    } 
 
    private ConcurrentCollections() { 
 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:
 * @author Jeanfrancois Arcand 
 */ 
public class SessionCreationInterceptor extends AtmosphereInterceptorAdapter { 
 
    // This can cause memory leak. 
    private ConcurrentLinkedQueue<String> ids = new ConcurrentLinkedQueue<String>();
 
    @Override 
    public Action inspect(AtmosphereResource r) {
 
        if (Utils.webSocketMessage(r)) return Action.CONTINUE;
 
        if (r.session(false) == null
                && !ids.remove(r.uuid())
                && r.getRequest().getMethod().equalsIgnoreCase("GET")) {
            r.session(true);
            ids.offer(r.uuid());
            return Action.CANCELLED; 
        } 
        return Action.CONTINUE; 
8
CodeRank
This code example shows how to use the following methods:
 */ 
public class JettyCometSupport extends AsynchronousProcessor { 
 
    private static final Logger logger = LoggerFactory.getLogger(JettyCometSupport.class); 
 
    private final ConcurrentLinkedQueue<Continuation> resumed = new ConcurrentLinkedQueue<Continuation>();
 
    public JettyCometSupport(AtmosphereConfig config) {
        super(config);
    } 
 
    @Override 
    public Action service(AtmosphereRequest req, AtmosphereResponse response)
            throws IOException, ServletException {
        Continuation c = ContinuationSupport.getContinuation(req, null);
        Action action = null; 
 
        if (!c.isResumed() && !c.isPending() && req.getAttribute(FrameworkConfig.CANCEL_SUSPEND_OPERATION) == null) {
            // This will throw an exception 
            action = suspended(req, response);
8
CodeRank
This code example shows how to use the following methods:
package org.apache.hadoop.util; 
 
import java.util.concurrent.ConcurrentLinkedQueue; 
 
public class CoronaFailureEventInjector { 
  private ConcurrentLinkedQueue<CoronaFailureEvent> failureEventQueue;
   
  public CoronaFailureEventInjector(){ 
    failureEventQueue = new ConcurrentLinkedQueue<CoronaFailureEvent> ();
  } 
   
  public void injectFailureEvent(CoronaFailureEvent event) {
    failureEventQueue.offer(event);
  } 
   
  public CoronaFailureEvent pollFailureEvent() { 
    return failureEventQueue.poll();
  } 
   
  public static CoronaFailureEventInjector getInjectorFromStrings (String [] events, int start) {

7
CodeRank
This code example shows how to use the following methods:
    /* 
     * We have to use the f prefix until the next major release to ensure 
     * serialization compatibility.  
     * See https://github.com/junit-team/junit/issues/976 
     */ 
    private final Collection<Description> fChildren = new ConcurrentLinkedQueue<Description>();
    private final String fDisplayName;
    private final Serializable fUniqueId;
    private final Annotation[] fAnnotations;
    private volatile /* write-once */ Class<?> fTestClass;
 
    private Description(Class<?> clazz, String displayName, Annotation... annotations) {
        this(clazz, displayName, displayName, annotations);
    } 
 
    private Description(Class<?> testClass, String displayName, Serializable uniqueId, Annotation... annotations) {
        if ((displayName == null) || (displayName.length() == 0)) {
            throw new IllegalArgumentException(
                    "The display name must not be empty."); 
        } 
8
CodeRank
This code example shows how to use the following methods:offer, peek, size
		assertEquals("9 Aug 2009 01:56:14 GMT", date.toGMTString());
	} 
 
	@Test
	public void confirmConcurrentLinkedQueueOfferSemantics() { 
		ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<String>();
 
		assertTrue(queue.offer("a"));
		assertEquals(1, queue.size());
 
		assertTrue(queue.offer("b"));
		assertEquals(2, queue.size());
		assertEquals("a", queue.peek());
 
		assertTrue(queue.offer("a"));
		//assertEquals(2, queue.size()); 
		//assertEquals("b", queue.peek()); 
		assertEquals(3, queue.size());
		assertEquals("a", queue.peek());
	} 

7
CodeRank
This code example shows how to use the following methods:clear, add
 * @author tag 
 * @version $Id: ColorAllocator.java 1180 2013-02-15 18:40:47Z tgaskins $ 
 */ 
public class ColorAllocator 
{ 
    protected static ConcurrentLinkedQueue<Color> initialColors = new ConcurrentLinkedQueue<Color>();
 
    static 
    { 
        initializeColors(); 
    } 
 
    public static void initializeColors() 
    { 
        initialColors.clear();
 
        // Create some standard first-used colors. Just add to this list to define more. 
        initialColors.add(Color.YELLOW);
        initialColors.add(Color.GREEN);
        initialColors.add(Color.BLUE);

7
CodeRank
This code example shows how to use the following methods:
  public void returnBuffer(ByteBuffer buf) {
    buf.clear(); // reset mark, limit, etc
    int size = buf.capacity();
    Queue<WeakReference<ByteBuffer>> list = buffersBySize.get(size);
    if (list == null) {
      list = new ConcurrentLinkedQueue<WeakReference<ByteBuffer>>();
      Queue<WeakReference<ByteBuffer>> prev = buffersBySize.putIfAbsent(size, list);
      // someone else put a queue in the map before we did 
      if (prev != null) {
        list = prev;
      } 
    } 
    list.add(new WeakReference<ByteBuffer>(buf));
  } 
   
  /** 
   * Return the number of available buffers of a given size. 
   * This is used only for tests. 
   */ 
  @VisibleForTesting 
7
CodeRank
This code example shows how to use the following methods:size
    return _list.isEmpty(); 
  } 
 
  @Override 
  public int size() { 
    return _list.size(); 
  } 
 
  @Override 
  public Iterator<ContextRunnable> iterator() { 
    return _list.iterator(); 
  } 
 
  @Override 
  public void add(final ContextRunnable runnable) { 
    _list.add(runnable); 
  } 
 
  @Override 
  public ContextRunnable take() { 
7
CodeRank

Related Java 8 ConcurrentLinkedQueue Questions & Answers:

See Code Examples for Java 8 ConcurrentLinkedQueue Methods: