org.logicalcobwebs.concurrent
类 LinkedQueue

java.lang.Object
  继承者 org.logicalcobwebs.concurrent.LinkedQueue
所有已实现的接口:
Channel, Puttable, Takable

public class LinkedQueue
extends Object
implements Channel

A linked list based channel implementation. The algorithm avoids contention between puts and takes when the queue is not empty. Normally a put and a take can proceed simultaneously. (Although it does not allow multiple concurrent puts or takes.) This class tends to perform more efficently than other Channel implementations in producer/consumer applications.

[ Introduction to this package. ]


字段摘要
protected  LinkedNode head_
          Dummy header node of list.
protected  LinkedNode last_
          The last node of list.
protected  Object putLock_
          Helper monitor for managing access to last node.
protected  int waitingForTake_
          The number of threads waiting for a take.
 
构造方法摘要
LinkedQueue()
           
 
方法摘要
protected  Object extract()
          Main mechanics for take/poll
protected  void insert(Object x)
          Main mechanics for put/offer
 boolean isEmpty()
           
 boolean offer(Object x, long msecs)
          Place item in channel only if it can be accepted within msecs milliseconds.
 Object peek()
          Return, but do not remove object at head of Channel, or null if it is empty.
 Object poll(long msecs)
          Return and remove an item from channel only if one is available within msecs milliseconds.
 void put(Object x)
          Place item in the channel, possibly waiting indefinitely until it can be accepted.
 Object take()
          Return and remove an item from channel, possibly waiting indefinitely until such an item exists.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

head_

protected LinkedNode head_
Dummy header node of list. The first actual node, if it exists, is always at head_.next. After each take, the old first node becomes the head.


putLock_

protected final Object putLock_
Helper monitor for managing access to last node.


last_

protected LinkedNode last_
The last node of list. Put() appends to list, so modifies last_


waitingForTake_

protected int waitingForTake_
The number of threads waiting for a take. Notifications are provided in put only if greater than zero. The bookkeeping is worth it here since in reasonably balanced usages, the notifications will hardly ever be necessary, so the call overhead to notify can be eliminated.

构造方法详细信息

LinkedQueue

public LinkedQueue()
方法详细信息

insert

protected void insert(Object x)
Main mechanics for put/offer


extract

protected Object extract()
Main mechanics for take/poll


put

public void put(Object x)
         throws InterruptedException
从接口 Channel 复制的描述
Place item in the channel, possibly waiting indefinitely until it can be accepted. Channels implementing the BoundedChannel subinterface are generally guaranteed to block on puts upon reaching capacity, but other implementations may or may not block.

指定者:
接口 Channel 中的 put
指定者:
接口 Puttable 中的 put
参数:
x - the element to be inserted. Should be non-null.
抛出:
InterruptedException - if the current thread has been interrupted at a point at which interruption is detected, in which case the element is guaranteed not to be inserted. Otherwise, on normal return, the element is guaranteed to have been inserted.

offer

public boolean offer(Object x,
                     long msecs)
              throws InterruptedException
从接口 Channel 复制的描述
Place item in channel only if it can be accepted within msecs milliseconds. The time bound is interpreted in a coarse-grained, best-effort fashion.

指定者:
接口 Channel 中的 offer
指定者:
接口 Puttable 中的 offer
参数:
x - the element to be inserted. Should be non-null.
msecs - the number of milliseconds to wait. If less than or equal to zero, the method does not perform any timed waits, but might still require access to a synchronization lock, which can impose unbounded delay if there is a lot of contention for the channel.
返回:
true if accepted, else false
抛出:
InterruptedException - if the current thread has been interrupted at a point at which interruption is detected, in which case the element is guaranteed not to be inserted (i.e., is equivalent to a false return).

take

public Object take()
            throws InterruptedException
从接口 Channel 复制的描述
Return and remove an item from channel, possibly waiting indefinitely until such an item exists.

指定者:
接口 Channel 中的 take
指定者:
接口 Takable 中的 take
返回:
some item from the channel. Different implementations may guarantee various properties (such as FIFO) about that item
抛出:
InterruptedException - if the current thread has been interrupted at a point at which interruption is detected, in which case state of the channel is unchanged.

peek

public Object peek()
从接口 Channel 复制的描述
Return, but do not remove object at head of Channel, or null if it is empty.

指定者:
接口 Channel 中的 peek

isEmpty

public boolean isEmpty()

poll

public Object poll(long msecs)
            throws InterruptedException
从接口 Channel 复制的描述
Return and remove an item from channel only if one is available within msecs milliseconds. The time bound is interpreted in a coarse grained, best-effort fashion.

指定者:
接口 Channel 中的 poll
指定者:
接口 Takable 中的 poll
参数:
msecs - the number of milliseconds to wait. If less than or equal to zero, the operation does not perform any timed waits, but might still require access to a synchronization lock, which can impose unbounded delay if there is a lot of contention for the channel.
返回:
some item, or null if the channel is empty.
抛出:
InterruptedException - if the current thread has been interrupted at a point at which interruption is detected, in which case state of the channel is unchanged (i.e., equivalent to a null return).


Copyright © 2014. All rights reserved.