Top Description Inners Fields Constructors Methods
org.apache.tomcat.jdbc.pool

public Class MultiLockFairBlockingQueue<E>

extends Object
implements BlockingQueue<E>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.BlockingQueue, java.util.Queue, java.util.Collection, java.lang.Iterable
Type Parameters
<E>
Type of element in the queue
Imports
java.util.ArrayList, .Collection, .Iterator, .LinkedList, .NoSuchElementException, java.util.concurrent.BlockingQueue, .CountDownLatch, .ExecutionException, .Future, .TimeUnit, .TimeoutException, java.util.concurrent.atomic.AtomicInteger, java.util.concurrent.locks.ReentrantLock

EXPERIMENTAL AND NOT YET COMPLETE! An implementation of a blocking queue with fairness waiting and lock dispersal to avoid contention. invocations to method poll(...) will get handed out in the order they were received. Locking is fine grained, a shared lock is only used during the first level of contention, waiting is done in a lock per thread basis so that order is guaranteed once the thread goes into a suspended monitor state.
Not all of the methods of the java.util.concurrent.BlockingQueue are implemented.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
protected class
protected class

Field Summary

Modifier and TypeField and Description
pack-priv final LinkedList<E>[]
items

All the objects in the pool are stored in a simple linked list

pack-priv final int
private final ReentrantLock[]
locks

Phase one entry lock in order to give out per-thread-locks for the waiting phase we have a phase one lock during the contention period.

pack-priv final AtomicInteger
pack-priv final AtomicInteger
pack-priv final LinkedList<MultiLockFairBlockingQueue<E>.ExchangeCountDownLatch<E>>[]
waiters

All threads waiting for an object are stored in a linked list

Constructor Summary

AccessConstructor and Description
public
MultiLockFairBlockingQueue()

Creates a new fair blocking queue.

Method Summary

Modifier and TypeMethod and Description
public boolean
add(E
the element to add
e
)

Implements java.util.concurrent.BlockingQueue.add.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

public boolean
addAll(Collection<? extends E>
collection containing elements to be added to this collection
c
)

Implements java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation).

public void
clear()

Implements java.util.Collection.clear.

Removes all of the elements from this collection (optional operation).

public boolean
contains(Object
object to be checked for containment in this queue
e
)

Implements java.util.concurrent.BlockingQueue.contains.

Returns true if this queue contains the specified element.

public boolean
containsAll(Collection<?>
collection to be checked for containment in this collection
c
)

Implements java.util.Collection.containsAll.

Returns true if this collection contains all of the elements in the specified collection.

public int
drainTo(Collection<? super E>
the collection to transfer elements into
c
,
int
the maximum number of elements to transfer
maxElements
)

Implements java.util.concurrent.BlockingQueue.drainTo.

Removes at most the given number of available elements from this queue and adds them to the given collection.

public int
drainTo(Collection<? super E>
the collection to transfer elements into
c
)

Implements java.util.concurrent.BlockingQueue.drainTo.

Removes all available elements from this queue and adds them to the given collection.

public E
element()

Implements java.util.Queue.element.

Retrieves, but does not remove, the head of this queue.

public int
public int
public boolean
isEmpty()

Implements java.util.Collection.isEmpty.

Returns true if this collection contains no elements.

public Iterator<E>
iterator()

Implements java.util.Collection.iterator.

Returns an iterator over the elements in this collection.

public boolean
offer(E
the element to add
e
)

Implements java.util.concurrent.BlockingQueue.offer.

Will always return true, queue is unbounded.

public boolean
offer(E
the element to add
e
,
long
how long to wait before giving up, in units of unit
timeout
,
TimeUnit
a TimeUnit determining how to interpret the timeout parameter
unit
)

Implements java.util.concurrent.BlockingQueue.offer.

Will never timeout, as it invokes the offer(Object) method.

public E
peek()

Implements java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

public E
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
)

Implements java.util.concurrent.BlockingQueue.poll.

Fair retrieval of an object in the queue.

public E
poll()

Implements java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.

public Future<E>

Returns:

- a future pending the result from the queue poll request
pollAsync
()

Request an item from the queue asynchronously

public void
put(E
the element to add
e
)

Implements java.util.concurrent.BlockingQueue.put.

Inserts the specified element into this queue, waiting if necessary for space to become available.

public int
remainingCapacity()

Implements java.util.concurrent.BlockingQueue.remainingCapacity.

Returns the number of additional elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking, or Integer.MAX_VALUE if there is no intrinsic limit.

public boolean
remove(Object
element to be removed from this queue, if present
e
)

Implements java.util.concurrent.BlockingQueue.remove.

Removes a single instance of the specified element from this queue, if it is present.

public E
remove()

Implements java.util.Queue.remove.

Retrieves and removes the head of this queue.

public boolean
removeAll(Collection<?>
collection containing elements to be removed from this collection
c
)

Implements java.util.Collection.removeAll.

Removes all of this collection's elements that are also contained in the specified collection (optional operation).

public boolean
retainAll(Collection<?>
collection containing elements to be retained in this collection
c
)

Implements java.util.Collection.retainAll.

Retains only the elements in this collection that are contained in the specified collection (optional operation).

public int
size()

Implements java.util.Collection.size.

Returns the number of elements in this collection.

public E
take()

Implements java.util.concurrent.BlockingQueue.take.

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

public Object[]
toArray()

Implements java.util.Collection.toArray.

Returns an array containing all of the elements in this collection.

public <T> T[]
toArray(T[]
the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
a
)

Implements java.util.Collection.toArray.

Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

itemsback to summary
pack-priv final LinkedList<E>[] items

All the objects in the pool are stored in a simple linked list

LOCK_COUNTback to summary
pack-priv final int LOCK_COUNT
locksback to summary
private final ReentrantLock[] locks

Phase one entry lock in order to give out per-thread-locks for the waiting phase we have a phase one lock during the contention period.

pollQueueback to summary
pack-priv final AtomicInteger pollQueue
putQueueback to summary
pack-priv final AtomicInteger putQueue
waitersback to summary
pack-priv final LinkedList<MultiLockFairBlockingQueue<E>.ExchangeCountDownLatch<E>>[] waiters

All threads waiting for an object are stored in a linked list

Constructor Detail

MultiLockFairBlockingQueueback to summary
public MultiLockFairBlockingQueue()

Creates a new fair blocking queue.

Annotations
@SuppressWarnings:unchecked

Method Detail

addback to summary
public boolean add(E e)

Implements java.util.concurrent.BlockingQueue.add.

Doc from java.util.concurrent.BlockingQueue.add.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available. When using a capacity-restricted queue, it is generally preferable to use offer.

Parameters
e:E

the element to add

Returns:boolean

true (as specified by Collection#add)

Annotations
@Override
addAllback to summary
public boolean addAll(Collection<? extends E> c)

Implements java.util.Collection.addAll.

Doc from java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.) If the specified collection has a defined encounter order, processing of its elements generally occurs in that order.

Parameters
c:Collection<? extends E>

collection containing elements to be added to this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
clearback to summary
public void clear()

Implements java.util.Collection.clear.

Doc from java.util.Collection.clear.

Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.

Annotations
@Override
Exceptions
UnsupportedOperationException:
- this operation is not supported
containsback to summary
public boolean contains(Object e)

Implements java.util.concurrent.BlockingQueue.contains.

Doc from java.util.concurrent.BlockingQueue.contains.

Returns true if this queue contains the specified element. More formally, returns true if and only if this queue contains at least one element e such that o.equals(e).

Parameters
e:Object

object to be checked for containment in this queue

Returns:boolean

true if this queue contains the specified element

Annotations
@Override
containsAllback to summary
public boolean containsAll(Collection<?> c)

Implements java.util.Collection.containsAll.

Doc from java.util.Collection.containsAll.

Returns true if this collection contains all of the elements in the specified collection.

Parameters
c:Collection<?>

collection to be checked for containment in this collection

Returns:boolean

true if this collection contains all of the elements in the specified collection

Annotations
@Override
Exceptions
UnsupportedOperationException:
- this operation is not supported
drainToback to summary
public int drainTo(Collection<? super E> c, int maxElements)

Implements java.util.concurrent.BlockingQueue.drainTo.

Doc from java.util.concurrent.BlockingQueue.drainTo.

Removes at most the given number of available elements from this queue and adds them to the given collection. A failure encountered while attempting to add elements to collection c may result in elements being in neither, either or both collections when the associated exception is thrown. Attempts to drain a queue to itself result in IllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

Parameters
c:Collection<? super E>

the collection to transfer elements into

maxElements:int

the maximum number of elements to transfer

Returns:int

the number of elements transferred

Annotations
@Override
Exceptions
UnsupportedOperationException:
- this operation is not supported
drainToback to summary
public int drainTo(Collection<? super E> c)

Implements java.util.concurrent.BlockingQueue.drainTo.

Doc from java.util.concurrent.BlockingQueue.drainTo.

Removes all available elements from this queue and adds them to the given collection. This operation may be more efficient than repeatedly polling this queue. A failure encountered while attempting to add elements to collection c may result in elements being in neither, either or both collections when the associated exception is thrown. Attempts to drain a queue to itself result in IllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

Parameters
c:Collection<? super E>

the collection to transfer elements into

Returns:int

the number of elements transferred

Annotations
@Override
Exceptions
UnsupportedOperationException:
- this operation is not supported
elementback to summary
public E element()

Implements java.util.Queue.element.

Doc from java.util.Queue.element.

Retrieves, but does not remove, the head of this queue. This method differs from peek only in that it throws an exception if this queue is empty.

Returns:E

the head of this queue

Annotations
@Override
Exceptions
UnsupportedOperationException:
- this operation is not supported
getNextPollback to summary
public int getNextPoll()
getNextPutback to summary
public int getNextPut()
isEmptyback to summary
public boolean isEmpty()

Implements java.util.Collection.isEmpty.

Doc from java.util.Collection.isEmpty.

Returns true if this collection contains no elements.

Returns:boolean

true if this collection contains no elements

Annotations
@Override
iteratorback to summary
public Iterator<E> iterator()

Implements java.util.Collection.iterator.

Doc from java.util.Collection.iterator.

Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).

Returns:Iterator<E>

an Iterator over the elements in this collection

Annotations
@Override
offerback to summary
public boolean offer(E e)

Implements java.util.concurrent.BlockingQueue.offer.

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

Will always return true, queue is unbounded. Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and false if no space is currently available. When using a capacity-restricted queue, this method is generally preferable to add, which can fail to insert an element only by throwing an exception.

Parameters
e:E

the element to add

Returns:boolean

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

Annotations
@Override
offerback to summary
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException

Implements java.util.concurrent.BlockingQueue.offer.

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

Will never timeout, as it invokes the offer(Object) method. Once a lock has been acquired, the Inserts the specified element into this queue, waiting up to the specified wait time if necessary for space to become available.

Parameters
e:E

the element to add

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:boolean

true if successful, or false if the specified waiting time elapses before space is available

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
peekback to summary
public E peek()

Implements java.util.Queue.peek.

Doc from java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Returns:E

the head of this queue, or null if this queue is empty

Annotations
@Override
Exceptions
UnsupportedOperationException:
- this operation is not supported
pollback to summary
public E poll(long timeout, TimeUnit unit) throws InterruptedException

Implements java.util.concurrent.BlockingQueue.poll.

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

Fair retrieval of an object in the queue. Objects are returned in the order the threads requested them. 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:E

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
pollback to summary
public E poll()

Implements java.util.Queue.poll.

Doc from java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Returns:E

the head of this queue, or null if this queue is empty

Annotations
@Override
pollAsyncback to summary
public Future<E> pollAsync()

Request an item from the queue asynchronously

Returns:Future<E>

- a future pending the result from the queue poll request

putback to summary
public void put(E e) throws InterruptedException

Implements java.util.concurrent.BlockingQueue.put.

Doc from java.util.concurrent.BlockingQueue.put.

Inserts the specified element into this queue, waiting if necessary for space to become available.

Parameters
e:E

the element to add

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
remainingCapacityback to summary
public int remainingCapacity()

Implements java.util.concurrent.BlockingQueue.remainingCapacity.

Doc from java.util.concurrent.BlockingQueue.remainingCapacity.

Returns the number of additional elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking, or Integer.MAX_VALUE if there is no intrinsic limit.

Note that you cannot always tell if an attempt to insert an element will succeed by inspecting remainingCapacity because it may be the case that another thread is about to insert or remove an element.

Returns:int

the remaining capacity

Annotations
@Override
removeback to summary
public boolean remove(Object e)

Implements java.util.concurrent.BlockingQueue.remove.

Doc from java.util.concurrent.BlockingQueue.remove.

Removes a single instance of the specified element from this queue, if it is present. More formally, removes an element e such that o.equals(e), if this queue contains one or more such elements. Returns true if this queue contained the specified element (or equivalently, if this queue changed as a result of the call).

Parameters
e:Object

element to be removed from this queue, if present

Returns:boolean

true if this queue changed as a result of the call

Annotations
@Override
removeback to summary
public E remove()

Implements java.util.Queue.remove.

Doc from java.util.Queue.remove.

Retrieves and removes the head of this queue. This method differs from poll() only in that it throws an exception if this queue is empty.

Returns:E

the head of this queue

Annotations
@Override
Exceptions
UnsupportedOperationException:
- this operation is not supported
removeAllback to summary
public boolean removeAll(Collection<?> c)

Implements java.util.Collection.removeAll.

Doc from java.util.Collection.removeAll.

Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.

Parameters
c:Collection<?>

collection containing elements to be removed from this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
Exceptions
UnsupportedOperationException:
- this operation is not supported
retainAllback to summary
public boolean retainAll(Collection<?> c)

Implements java.util.Collection.retainAll.

Doc from java.util.Collection.retainAll.

Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.

Parameters
c:Collection<?>

collection containing elements to be retained in this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
Exceptions
UnsupportedOperationException:
- this operation is not supported
sizeback to summary
public int size()

Implements java.util.Collection.size.

Doc from java.util.Collection.size.

Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this collection

Annotations
@Override
takeback to summary
public E take() throws InterruptedException

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:E

the head of this queue

Annotations
@Override
Exceptions
InterruptedException:
if interrupted while waiting
toArrayback to summary
public Object[] toArray()

Implements java.util.Collection.toArray.

Doc from java.util.Collection.toArray.

Returns an array containing all of the elements in this collection. If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. The returned array's runtime component type is Object.

The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.

Returns:Object[]

an array, whose runtime component type is Object, containing all of the elements in this collection

Annotations
@Override
Exceptions
UnsupportedOperationException:
- this operation is not supported
toArrayback to summary
public <T> T[] toArray(T[] a)

Implements java.util.Collection.toArray.

Doc from java.util.Collection.toArray.

Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.

If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of this collection only if the caller knows that this collection does not contain any null elements.)

If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

Parameters
<T>
the component type of the array to contain the collection
a:T[]

the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.

Returns:T[]

an array containing all of the elements in this collection

Annotations
@Override
Exceptions
UnsupportedOperationException:
- this operation is not supported
org.apache.tomcat.jdbc.pool back to summary

protected Class MultiLockFairBlockingQueue.ExchangeCountDownLatch<T>

extends CountDownLatch
Class Inheritance

Field Summary

Modifier and TypeField and Description
protected volatile T

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public T
public void
setItem(T item)

Inherited from java.util.concurrent.CountDownLatch:
awaitawaitcountDowngetCounttoString

Field Detail

itemback to summary
protected volatile T item

Constructor Detail

ExchangeCountDownLatchback to summary
public ExchangeCountDownLatch(int i)

Method Detail

getItemback to summary
public T getItem()
setItemback to summary
public void setItem(T item)
org.apache.tomcat.jdbc.pool back to summary

protected Class MultiLockFairBlockingQueue.FairIterator

extends Object
implements Iterator<E>
Class Inheritance
  • java.lang.Object
  • org.apache.tomcat.jdbc.pool.MultiLockFairBlockingQueue.FairIterator
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
pack-priv E
pack-priv E[]
pack-priv int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public E
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

elementback to summary
pack-priv E element
elementsback to summary
pack-priv E[] elements
indexback to summary
pack-priv int index

Constructor Detail

FairIteratorback to summary
public FairIterator()
Annotations
@SuppressWarnings:unchecked

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public E next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:E

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
org.apache.tomcat.jdbc.pool back to summary

protected Class MultiLockFairBlockingQueue.ItemFuture<T>

extends Object
implements Future<T>
Class Inheritance
  • java.lang.Object
  • org.apache.tomcat.jdbc.pool.MultiLockFairBlockingQueue.ItemFuture
All Implemented Interfaces
java.util.concurrent.Future

Field Summary

Modifier and TypeField and Description
protected volatile boolean
protected volatile T
protected volatile MultiLockFairBlockingQueue<E>.ExchangeCountDownLatch<T>

Constructor Summary

AccessConstructor and Description
public
ItemFuture(T item)

public

Method Summary

Modifier and TypeMethod and Description
public boolean
cancel(boolean
true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete
mayInterruptIfRunning
)

Implements java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task.

public T
get()

Implements java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

public T
get(long
the maximum time to wait
timeout
,
TimeUnit
the time unit of the timeout argument
unit
)

Implements java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

public boolean
isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

public boolean
isDone()

Implements java.util.concurrent.Future.isDone.

Returns true if this task completed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

canceledback to summary
protected volatile boolean canceled
itemback to summary
protected volatile T item
latchback to summary
protected volatile MultiLockFairBlockingQueue<E>.ExchangeCountDownLatch<T> latch

Constructor Detail

ItemFutureback to summary
public ItemFuture(T item)
ItemFutureback to summary
public ItemFuture(MultiLockFairBlockingQueue<E>.ExchangeCountDownLatch<T> latch)

Method Detail

cancelback to summary
public boolean cancel(boolean mayInterruptIfRunning)

Implements java.util.concurrent.Future.cancel.

Doc from java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task. This method has no effect if the task is already completed or cancelled, or could not be cancelled for some other reason. Otherwise, if this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task (when known by the implementation) is interrupted in an attempt to stop the task.

The return value from this method does not necessarily indicate whether the task is now cancelled; use isCancelled.

Parameters
mayInterruptIfRunning:boolean

true if the thread executing this task should be interrupted (if the thread is known to the implementation); otherwise, in-progress tasks are allowed to complete

Returns:boolean

false if the task could not be cancelled, typically because it has already completed; true otherwise. If two or more threads cause a task to be cancelled, then at least one of them returns true. Implementations may provide stronger guarantees.

Annotations
@Override
getback to summary
public T get() throws InterruptedException, ExecutionException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for the computation to complete, and then retrieves its result.

Returns:T

the computed result

Annotations
@Override
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception
getback to summary
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException

Implements java.util.concurrent.Future.get.

Doc from java.util.concurrent.Future.get.

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Parameters
timeout:long

the maximum time to wait

unit:TimeUnit

the time unit of the timeout argument

Returns:T

the computed result

Annotations
@Override
Exceptions
InterruptedException:
if the current thread was interrupted while waiting
ExecutionException:
if the computation threw an exception
TimeoutException:
if the wait timed out
isCancelledback to summary
public boolean isCancelled()

Implements java.util.concurrent.Future.isCancelled.

Doc from java.util.concurrent.Future.isCancelled.

Returns true if this task was cancelled before it completed normally.

Returns:boolean

true if this task was cancelled before it completed

Annotations
@Override
isDoneback to summary
public boolean isDone()

Implements java.util.concurrent.Future.isDone.

Doc from java.util.concurrent.Future.isDone.

Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.

Returns:boolean

true if this task completed

Annotations
@Override