Top Description Fields Constructors Methods
org.apache.tomcat.util.threads

public Class TaskQueue

extends LinkedBlockingQueue<Runnable>
Class Inheritance
Imports
java.util.Collection, java.util.concurrent.LinkedBlockingQueue, .RejectedExecutionException, .TimeUnit, org.apache.tomcat.util.res.StringManager

As task queue specifically designed to run with a thread pool executor. The task queue is optimised to properly utilize threads within a thread pool executor. If you use a normal queue, the executor will spawn threads when there are idle threads and you won't be able to force items onto the queue itself.

Field Summary

Modifier and TypeField and Description
private transient volatile ThreadPoolExecutor
private static final long
protected static final StringManager

Constructor Summary

AccessConstructor and Description
public
public
TaskQueue(int capacity)

public

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the task was added to the queue, otherwise false
force
(Runnable
The task to add to the queue
o
)

Used to add a task to the queue if the task has been rejected by the Executor.

public boolean
offer(Runnable
the element to add
o
)

Overrides java.util.concurrent.LinkedBlockingQueue.offer.

Implements java.util.concurrent.BlockingQueue.offer, java.util.Queue.offer.

Inserts the specified element at the tail of this queue if it is possible to do so immediately without exceeding the queue's capacity, returning true upon success and false if this queue is full.

public Runnable
poll(long
how long to wait before giving up, in units of unit
timeout
,
TimeUnit
a TimeUnit determining how to interpret the timeout parameter
unit
)

Overrides java.util.concurrent.LinkedBlockingQueue.poll.

Implements java.util.concurrent.BlockingQueue.poll.

Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.

public void
public Runnable
take()

Overrides java.util.concurrent.LinkedBlockingQueue.take.

Implements java.util.concurrent.BlockingQueue.take.

Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.

Inherited from java.util.concurrent.LinkedBlockingQueue:
clearcontainsdrainTodrainToforEachiteratorofferpeekpollputremainingCapacityremoveremoveAllremoveIfretainAllsizespliteratortoArraytoArraytoString

Field Detail

parentback to summary
private transient volatile ThreadPoolExecutor parent
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.LinkedBlockingQueue.serialVersionUID.

smback to summary
protected static final StringManager sm

Constructor Detail

TaskQueueback to summary
public TaskQueue()
TaskQueueback to summary
public TaskQueue(int capacity)
TaskQueueback to summary
public TaskQueue(Collection<? extends Runnable> c)

Method Detail

forceback to summary
public boolean force(Runnable o)

Used to add a task to the queue if the task has been rejected by the Executor.

Parameters
o:Runnable

The task to add to the queue

Returns:boolean

true if the task was added to the queue, otherwise false

offerback to summary
public boolean offer(Runnable o)

Overrides java.util.concurrent.LinkedBlockingQueue.offer.

Implements java.util.concurrent.BlockingQueue.offer, java.util.Queue.offer.

Doc from java.util.concurrent.LinkedBlockingQueue.offer.

Inserts the specified element at the tail of this queue if it is possible to do so immediately without exceeding the queue's capacity, returning true upon success and false if this queue is full. When using a capacity-restricted queue, this method is generally preferable to method add, which can fail to insert an element only by throwing an exception.

Parameters
o:Runnable

Doc from java.util.concurrent.BlockingQueue.offer.

the element to add

Returns:boolean

Doc from java.util.concurrent.BlockingQueue.offer.

true if the element was added to this queue, else false

Annotations
@Override
pollback to summary
public Runnable poll(long timeout, TimeUnit unit) throws InterruptedException

Overrides java.util.concurrent.LinkedBlockingQueue.poll.

Implements java.util.concurrent.BlockingQueue.poll.

Doc from java.util.concurrent.BlockingQueue.poll.

Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.

Parameters
timeout:long

how long to wait before giving up, in units of unit

unit:TimeUnit

a TimeUnit determining how to interpret the timeout parameter

Returns:Runnable

the head of this queue, or null if the specified waiting time elapses before an element is available

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
setParentback to summary
public void setParent(ThreadPoolExecutor tp)
takeback to summary
public Runnable take() throws InterruptedException

Overrides java.util.concurrent.LinkedBlockingQueue.take.

Implements java.util.concurrent.BlockingQueue.take.

Doc from java.util.concurrent.BlockingQueue.take.

Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.

Returns:Runnable

the head of this queue

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting