15 |
|
* operation must wait for a corresponding remove operation by another |
16 |
|
* thread, and vice versa. A synchronous queue does not have any |
17 |
|
* internal capacity, not even a capacity of one. You cannot |
18 |
< |
* <tt>peek</tt> at a synchronous queue because an element is only |
18 |
> |
* {@code peek} at a synchronous queue because an element is only |
19 |
|
* present when you try to remove it; you cannot insert an element |
20 |
|
* (using any method) unless another thread is trying to remove it; |
21 |
|
* you cannot iterate as there is nothing to iterate. The |
22 |
|
* <em>head</em> of the queue is the element that the first queued |
23 |
|
* inserting thread is trying to add to the queue; if there is no such |
24 |
|
* queued thread then no element is available for removal and |
25 |
< |
* <tt>poll()</tt> will return <tt>null</tt>. For purposes of other |
26 |
< |
* <tt>Collection</tt> methods (for example <tt>contains</tt>), a |
27 |
< |
* <tt>SynchronousQueue</tt> acts as an empty collection. This queue |
28 |
< |
* does not permit <tt>null</tt> elements. |
25 |
> |
* {@code poll()} will return {@code null}. For purposes of other |
26 |
> |
* {@code Collection} methods (for example {@code contains}), a |
27 |
> |
* {@code SynchronousQueue} acts as an empty collection. This queue |
28 |
> |
* does not permit {@code null} elements. |
29 |
|
* |
30 |
|
* <p>Synchronous queues are similar to rendezvous channels used in |
31 |
|
* CSP and Ada. They are well suited for handoff designs, in which an |
36 |
|
* <p>This class supports an optional fairness policy for ordering |
37 |
|
* waiting producer and consumer threads. By default, this ordering |
38 |
|
* is not guaranteed. However, a queue constructed with fairness set |
39 |
< |
* to <tt>true</tt> grants threads access in FIFO order. |
39 |
> |
* to {@code true} grants threads access in FIFO order. |
40 |
|
* |
41 |
|
* <p>This class and its iterator implement all of the |
42 |
|
* <em>optional</em> methods of the {@link Collection} and {@link |
818 |
|
private transient volatile Transferer<E> transferer; |
819 |
|
|
820 |
|
/** |
821 |
< |
* Creates a <tt>SynchronousQueue</tt> with nonfair access policy. |
821 |
> |
* Creates a {@code SynchronousQueue} with nonfair access policy. |
822 |
|
*/ |
823 |
|
public SynchronousQueue() { |
824 |
|
this(false); |
825 |
|
} |
826 |
|
|
827 |
|
/** |
828 |
< |
* Creates a <tt>SynchronousQueue</tt> with the specified fairness policy. |
828 |
> |
* Creates a {@code SynchronousQueue} with the specified fairness policy. |
829 |
|
* |
830 |
|
* @param fair if true, waiting threads contend in FIFO order for |
831 |
|
* access; otherwise the order is unspecified. |
853 |
|
* Inserts the specified element into this queue, waiting if necessary |
854 |
|
* up to the specified wait time for another thread to receive it. |
855 |
|
* |
856 |
< |
* @return <tt>true</tt> if successful, or <tt>false</tt> if the |
856 |
> |
* @return {@code true} if successful, or {@code false} if the |
857 |
|
* specified waiting time elapses before a consumer appears. |
858 |
|
* @throws InterruptedException {@inheritDoc} |
859 |
|
* @throws NullPointerException {@inheritDoc} |
873 |
|
* waiting to receive it. |
874 |
|
* |
875 |
|
* @param e the element to add |
876 |
< |
* @return <tt>true</tt> if the element was added to this queue, else |
877 |
< |
* <tt>false</tt> |
876 |
> |
* @return {@code true} if the element was added to this queue, else |
877 |
> |
* {@code false} |
878 |
|
* @throws NullPointerException if the specified element is null |
879 |
|
*/ |
880 |
|
public boolean offer(E e) { |
902 |
|
* if necessary up to the specified wait time, for another thread |
903 |
|
* to insert it. |
904 |
|
* |
905 |
< |
* @return the head of this queue, or <tt>null</tt> if the |
905 |
> |
* @return the head of this queue, or {@code null} if the |
906 |
|
* specified waiting time elapses before an element is present. |
907 |
|
* @throws InterruptedException {@inheritDoc} |
908 |
|
*/ |
917 |
|
* Retrieves and removes the head of this queue, if another thread |
918 |
|
* is currently making an element available. |
919 |
|
* |
920 |
< |
* @return the head of this queue, or <tt>null</tt> if no |
920 |
> |
* @return the head of this queue, or {@code null} if no |
921 |
|
* element is available. |
922 |
|
*/ |
923 |
|
public E poll() { |
925 |
|
} |
926 |
|
|
927 |
|
/** |
928 |
< |
* Always returns <tt>true</tt>. |
929 |
< |
* A <tt>SynchronousQueue</tt> has no internal capacity. |
928 |
> |
* Always returns {@code true}. |
929 |
> |
* A {@code SynchronousQueue} has no internal capacity. |
930 |
|
* |
931 |
< |
* @return <tt>true</tt> |
931 |
> |
* @return {@code true} |
932 |
|
*/ |
933 |
|
public boolean isEmpty() { |
934 |
|
return true; |
936 |
|
|
937 |
|
/** |
938 |
|
* Always returns zero. |
939 |
< |
* A <tt>SynchronousQueue</tt> has no internal capacity. |
939 |
> |
* A {@code SynchronousQueue} has no internal capacity. |
940 |
|
* |
941 |
|
* @return zero |
942 |
|
*/ |
946 |
|
|
947 |
|
/** |
948 |
|
* Always returns zero. |
949 |
< |
* A <tt>SynchronousQueue</tt> has no internal capacity. |
949 |
> |
* A {@code SynchronousQueue} has no internal capacity. |
950 |
|
* |
951 |
|
* @return zero |
952 |
|
*/ |
956 |
|
|
957 |
|
/** |
958 |
|
* Does nothing. |
959 |
< |
* A <tt>SynchronousQueue</tt> has no internal capacity. |
959 |
> |
* A {@code SynchronousQueue} has no internal capacity. |
960 |
|
*/ |
961 |
|
public void clear() { |
962 |
|
} |
963 |
|
|
964 |
|
/** |
965 |
< |
* Always returns <tt>false</tt>. |
966 |
< |
* A <tt>SynchronousQueue</tt> has no internal capacity. |
965 |
> |
* Always returns {@code false}. |
966 |
> |
* A {@code SynchronousQueue} has no internal capacity. |
967 |
|
* |
968 |
|
* @param o the element |
969 |
< |
* @return <tt>false</tt> |
969 |
> |
* @return {@code false} |
970 |
|
*/ |
971 |
|
public boolean contains(Object o) { |
972 |
|
return false; |
973 |
|
} |
974 |
|
|
975 |
|
/** |
976 |
< |
* Always returns <tt>false</tt>. |
977 |
< |
* A <tt>SynchronousQueue</tt> has no internal capacity. |
976 |
> |
* Always returns {@code false}. |
977 |
> |
* A {@code SynchronousQueue} has no internal capacity. |
978 |
|
* |
979 |
|
* @param o the element to remove |
980 |
< |
* @return <tt>false</tt> |
980 |
> |
* @return {@code false} |
981 |
|
*/ |
982 |
|
public boolean remove(Object o) { |
983 |
|
return false; |
984 |
|
} |
985 |
|
|
986 |
|
/** |
987 |
< |
* Returns <tt>false</tt> unless the given collection is empty. |
988 |
< |
* A <tt>SynchronousQueue</tt> has no internal capacity. |
987 |
> |
* Returns {@code false} unless the given collection is empty. |
988 |
> |
* A {@code SynchronousQueue} has no internal capacity. |
989 |
|
* |
990 |
|
* @param c the collection |
991 |
< |
* @return <tt>false</tt> unless given collection is empty |
991 |
> |
* @return {@code false} unless given collection is empty |
992 |
|
*/ |
993 |
|
public boolean containsAll(Collection<?> c) { |
994 |
|
return c.isEmpty(); |
995 |
|
} |
996 |
|
|
997 |
|
/** |
998 |
< |
* Always returns <tt>false</tt>. |
999 |
< |
* A <tt>SynchronousQueue</tt> has no internal capacity. |
998 |
> |
* Always returns {@code false}. |
999 |
> |
* A {@code SynchronousQueue} has no internal capacity. |
1000 |
|
* |
1001 |
|
* @param c the collection |
1002 |
< |
* @return <tt>false</tt> |
1002 |
> |
* @return {@code false} |
1003 |
|
*/ |
1004 |
|
public boolean removeAll(Collection<?> c) { |
1005 |
|
return false; |
1006 |
|
} |
1007 |
|
|
1008 |
|
/** |
1009 |
< |
* Always returns <tt>false</tt>. |
1010 |
< |
* A <tt>SynchronousQueue</tt> has no internal capacity. |
1009 |
> |
* Always returns {@code false}. |
1010 |
> |
* A {@code SynchronousQueue} has no internal capacity. |
1011 |
|
* |
1012 |
|
* @param c the collection |
1013 |
< |
* @return <tt>false</tt> |
1013 |
> |
* @return {@code false} |
1014 |
|
*/ |
1015 |
|
public boolean retainAll(Collection<?> c) { |
1016 |
|
return false; |
1017 |
|
} |
1018 |
|
|
1019 |
|
/** |
1020 |
< |
* Always returns <tt>null</tt>. |
1021 |
< |
* A <tt>SynchronousQueue</tt> does not return elements |
1020 |
> |
* Always returns {@code null}. |
1021 |
> |
* A {@code SynchronousQueue} does not return elements |
1022 |
|
* unless actively waited on. |
1023 |
|
* |
1024 |
< |
* @return <tt>null</tt> |
1024 |
> |
* @return {@code null} |
1025 |
|
*/ |
1026 |
|
public E peek() { |
1027 |
|
return null; |
1028 |
|
} |
1029 |
|
|
1030 |
|
/** |
1031 |
< |
* Returns an empty iterator in which <tt>hasNext</tt> always returns |
1032 |
< |
* <tt>false</tt>. |
1031 |
> |
* Returns an empty iterator in which {@code hasNext} always returns |
1032 |
> |
* {@code false}. |
1033 |
|
* |
1034 |
|
* @return an empty iterator |
1035 |
|
*/ |
1057 |
|
} |
1058 |
|
|
1059 |
|
/** |
1060 |
< |
* Sets the zeroeth element of the specified array to <tt>null</tt> |
1060 |
> |
* Sets the zeroeth element of the specified array to {@code null} |
1061 |
|
* (if the array has non-zero length) and returns it. |
1062 |
|
* |
1063 |
|
* @param a the array |