提交 3459dfdc 编写于 作者: D dl

7003745: Code style cleanups (sync from Dougs CVS)

Reviewed-by: chegar, dholmes
上级 fe7ceb20
...@@ -96,14 +96,14 @@ public abstract class AbstractCollection<E> implements Collection<E> { ...@@ -96,14 +96,14 @@ public abstract class AbstractCollection<E> implements Collection<E> {
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException {@inheritDoc}
*/ */
public boolean contains(Object o) { public boolean contains(Object o) {
Iterator<E> e = iterator(); Iterator<E> it = iterator();
if (o==null) { if (o==null) {
while (e.hasNext()) while (it.hasNext())
if (e.next()==null) if (it.next()==null)
return true; return true;
} else { } else {
while (e.hasNext()) while (it.hasNext())
if (o.equals(e.next())) if (o.equals(it.next()))
return true; return true;
} }
return false; return false;
...@@ -269,18 +269,18 @@ public abstract class AbstractCollection<E> implements Collection<E> { ...@@ -269,18 +269,18 @@ public abstract class AbstractCollection<E> implements Collection<E> {
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException {@inheritDoc}
*/ */
public boolean remove(Object o) { public boolean remove(Object o) {
Iterator<E> e = iterator(); Iterator<E> it = iterator();
if (o==null) { if (o==null) {
while (e.hasNext()) { while (it.hasNext()) {
if (e.next()==null) { if (it.next()==null) {
e.remove(); it.remove();
return true; return true;
} }
} }
} else { } else {
while (e.hasNext()) { while (it.hasNext()) {
if (o.equals(e.next())) { if (o.equals(it.next())) {
e.remove(); it.remove();
return true; return true;
} }
} }
...@@ -304,9 +304,8 @@ public abstract class AbstractCollection<E> implements Collection<E> { ...@@ -304,9 +304,8 @@ public abstract class AbstractCollection<E> implements Collection<E> {
* @see #contains(Object) * @see #contains(Object)
*/ */
public boolean containsAll(Collection<?> c) { public boolean containsAll(Collection<?> c) {
Iterator<?> e = c.iterator(); for (Object e : c)
while (e.hasNext()) if (!contains(e))
if (!contains(e.next()))
return false; return false;
return true; return true;
} }
...@@ -331,11 +330,9 @@ public abstract class AbstractCollection<E> implements Collection<E> { ...@@ -331,11 +330,9 @@ public abstract class AbstractCollection<E> implements Collection<E> {
*/ */
public boolean addAll(Collection<? extends E> c) { public boolean addAll(Collection<? extends E> c) {
boolean modified = false; boolean modified = false;
Iterator<? extends E> e = c.iterator(); for (E e : c)
while (e.hasNext()) { if (add(e))
if (add(e.next()))
modified = true; modified = true;
}
return modified; return modified;
} }
...@@ -362,10 +359,10 @@ public abstract class AbstractCollection<E> implements Collection<E> { ...@@ -362,10 +359,10 @@ public abstract class AbstractCollection<E> implements Collection<E> {
*/ */
public boolean removeAll(Collection<?> c) { public boolean removeAll(Collection<?> c) {
boolean modified = false; boolean modified = false;
Iterator<?> e = iterator(); Iterator<?> it = iterator();
while (e.hasNext()) { while (it.hasNext()) {
if (c.contains(e.next())) { if (c.contains(it.next())) {
e.remove(); it.remove();
modified = true; modified = true;
} }
} }
...@@ -395,10 +392,10 @@ public abstract class AbstractCollection<E> implements Collection<E> { ...@@ -395,10 +392,10 @@ public abstract class AbstractCollection<E> implements Collection<E> {
*/ */
public boolean retainAll(Collection<?> c) { public boolean retainAll(Collection<?> c) {
boolean modified = false; boolean modified = false;
Iterator<E> e = iterator(); Iterator<E> it = iterator();
while (e.hasNext()) { while (it.hasNext()) {
if (!c.contains(e.next())) { if (!c.contains(it.next())) {
e.remove(); it.remove();
modified = true; modified = true;
} }
} }
...@@ -421,10 +418,10 @@ public abstract class AbstractCollection<E> implements Collection<E> { ...@@ -421,10 +418,10 @@ public abstract class AbstractCollection<E> implements Collection<E> {
* @throws UnsupportedOperationException {@inheritDoc} * @throws UnsupportedOperationException {@inheritDoc}
*/ */
public void clear() { public void clear() {
Iterator<E> e = iterator(); Iterator<E> it = iterator();
while (e.hasNext()) { while (it.hasNext()) {
e.next(); it.next();
e.remove(); it.remove();
} }
} }
...@@ -442,18 +439,18 @@ public abstract class AbstractCollection<E> implements Collection<E> { ...@@ -442,18 +439,18 @@ public abstract class AbstractCollection<E> implements Collection<E> {
* @return a string representation of this collection * @return a string representation of this collection
*/ */
public String toString() { public String toString() {
Iterator<E> i = iterator(); Iterator<E> it = iterator();
if (! i.hasNext()) if (! it.hasNext())
return "[]"; return "[]";
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append('['); sb.append('[');
for (;;) { for (;;) {
E e = i.next(); E e = it.next();
sb.append(e == this ? "(this Collection)" : e); sb.append(e == this ? "(this Collection)" : e);
if (! i.hasNext()) if (! it.hasNext())
return sb.append(']').toString(); return sb.append(']').toString();
sb.append(", "); sb.append(',').append(' ');
} }
} }
......
...@@ -175,15 +175,15 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements L ...@@ -175,15 +175,15 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements L
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException {@inheritDoc}
*/ */
public int indexOf(Object o) { public int indexOf(Object o) {
ListIterator<E> e = listIterator(); ListIterator<E> it = listIterator();
if (o==null) { if (o==null) {
while (e.hasNext()) while (it.hasNext())
if (e.next()==null) if (it.next()==null)
return e.previousIndex(); return it.previousIndex();
} else { } else {
while (e.hasNext()) while (it.hasNext())
if (o.equals(e.next())) if (o.equals(it.next()))
return e.previousIndex(); return it.previousIndex();
} }
return -1; return -1;
} }
...@@ -200,15 +200,15 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements L ...@@ -200,15 +200,15 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements L
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException {@inheritDoc}
*/ */
public int lastIndexOf(Object o) { public int lastIndexOf(Object o) {
ListIterator<E> e = listIterator(size()); ListIterator<E> it = listIterator(size());
if (o==null) { if (o==null) {
while (e.hasPrevious()) while (it.hasPrevious())
if (e.previous()==null) if (it.previous()==null)
return e.nextIndex(); return it.nextIndex();
} else { } else {
while (e.hasPrevious()) while (it.hasPrevious())
if (o.equals(e.previous())) if (o.equals(it.previous()))
return e.nextIndex(); return it.nextIndex();
} }
return -1; return -1;
} }
...@@ -517,7 +517,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements L ...@@ -517,7 +517,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements L
ListIterator<E> e1 = listIterator(); ListIterator<E> e1 = listIterator();
ListIterator e2 = ((List) o).listIterator(); ListIterator e2 = ((List) o).listIterator();
while(e1.hasNext() && e2.hasNext()) { while (e1.hasNext() && e2.hasNext()) {
E o1 = e1.next(); E o1 = e1.next();
Object o2 = e2.next(); Object o2 = e2.next();
if (!(o1==null ? o2==null : o1.equals(o2))) if (!(o1==null ? o2==null : o1.equals(o2)))
......
...@@ -523,7 +523,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> { ...@@ -523,7 +523,7 @@ public abstract class AbstractMap<K,V> implements Map<K,V> {
sb.append(value == this ? "(this Map)" : value); sb.append(value == this ? "(this Map)" : value);
if (! i.hasNext()) if (! i.hasNext())
return sb.append('}').toString(); return sb.append('}').toString();
sb.append(", "); sb.append(',').append(' ');
} }
} }
......
...@@ -120,9 +120,9 @@ public class ArrayList<E> extends AbstractList<E> ...@@ -120,9 +120,9 @@ public class ArrayList<E> extends AbstractList<E>
/** /**
* Constructs an empty list with the specified initial capacity. * Constructs an empty list with the specified initial capacity.
* *
* @param initialCapacity the initial capacity of the list * @param initialCapacity the initial capacity of the list
* @exception IllegalArgumentException if the specified initial capacity * @throws IllegalArgumentException if the specified initial capacity
* is negative * is negative
*/ */
public ArrayList(int initialCapacity) { public ArrayList(int initialCapacity) {
super(); super();
...@@ -173,7 +173,7 @@ public class ArrayList<E> extends AbstractList<E> ...@@ -173,7 +173,7 @@ public class ArrayList<E> extends AbstractList<E>
* necessary, to ensure that it can hold at least the number of elements * necessary, to ensure that it can hold at least the number of elements
* specified by the minimum capacity argument. * specified by the minimum capacity argument.
* *
* @param minCapacity the desired minimum capacity * @param minCapacity the desired minimum capacity
*/ */
public void ensureCapacity(int minCapacity) { public void ensureCapacity(int minCapacity) {
if (minCapacity > 0) if (minCapacity > 0)
......
...@@ -124,7 +124,7 @@ public class Collections { ...@@ -124,7 +124,7 @@ public class Collections {
* *
* <p>The implementation takes equal advantage of ascending and * <p>The implementation takes equal advantage of ascending and
* descending order in its input array, and can take advantage of * descending order in its input array, and can take advantage of
* ascending and descending order in different parts of the the same * ascending and descending order in different parts of the same
* input array. It is well-suited to merging two or more sorted arrays: * input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array. * simply concatenate the arrays and sort the resulting array.
* *
...@@ -184,7 +184,7 @@ public class Collections { ...@@ -184,7 +184,7 @@ public class Collections {
* *
* <p>The implementation takes equal advantage of ascending and * <p>The implementation takes equal advantage of ascending and
* descending order in its input array, and can take advantage of * descending order in its input array, and can take advantage of
* ascending and descending order in different parts of the the same * ascending and descending order in different parts of the same
* input array. It is well-suited to merging two or more sorted arrays: * input array. It is well-suited to merging two or more sorted arrays:
* simply concatenate the arrays and sort the resulting array. * simply concatenate the arrays and sort the resulting array.
* *
...@@ -823,7 +823,7 @@ public class Collections { ...@@ -823,7 +823,7 @@ public class Collections {
i -= size; i -= size;
displaced = list.set(i, displaced); displaced = list.set(i, displaced);
nMoved ++; nMoved ++;
} while(i != cycleStart); } while (i != cycleStart);
} }
} }
...@@ -1452,9 +1452,9 @@ public class Collections { ...@@ -1452,9 +1452,9 @@ public class Collections {
* when o is a Map.Entry, and calls o.setValue. * when o is a Map.Entry, and calls o.setValue.
*/ */
public boolean containsAll(Collection<?> coll) { public boolean containsAll(Collection<?> coll) {
Iterator<?> e = coll.iterator(); Iterator<?> it = coll.iterator();
while (e.hasNext()) while (it.hasNext())
if (!contains(e.next())) // Invokes safe contains() above if (!contains(it.next())) // Invokes safe contains() above
return false; return false;
return true; return true;
} }
...@@ -1482,12 +1482,12 @@ public class Collections { ...@@ -1482,12 +1482,12 @@ public class Collections {
UnmodifiableEntry(Map.Entry<? extends K, ? extends V> e) {this.e = e;} UnmodifiableEntry(Map.Entry<? extends K, ? extends V> e) {this.e = e;}
public K getKey() {return e.getKey();} public K getKey() {return e.getKey();}
public V getValue() {return e.getValue();} public V getValue() {return e.getValue();}
public V setValue(V value) { public V setValue(V value) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public int hashCode() {return e.hashCode();} public int hashCode() {return e.hashCode();}
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof Map.Entry)) if (!(o instanceof Map.Entry))
return false; return false;
...@@ -1495,7 +1495,7 @@ public class Collections { ...@@ -1495,7 +1495,7 @@ public class Collections {
return eq(e.getKey(), t.getKey()) && return eq(e.getKey(), t.getKey()) &&
eq(e.getValue(), t.getValue()); eq(e.getValue(), t.getValue());
} }
public String toString() {return e.toString();} public String toString() {return e.toString();}
} }
} }
} }
...@@ -1562,7 +1562,7 @@ public class Collections { ...@@ -1562,7 +1562,7 @@ public class Collections {
* <pre> * <pre>
* Collection c = Collections.synchronizedCollection(myCollection); * Collection c = Collections.synchronizedCollection(myCollection);
* ... * ...
* synchronized(c) { * synchronized (c) {
* Iterator i = c.iterator(); // Must be in the synchronized block * Iterator i = c.iterator(); // Must be in the synchronized block
* while (i.hasNext()) * while (i.hasNext())
* foo(i.next()); * foo(i.next());
...@@ -1611,19 +1611,19 @@ public class Collections { ...@@ -1611,19 +1611,19 @@ public class Collections {
} }
public int size() { public int size() {
synchronized(mutex) {return c.size();} synchronized (mutex) {return c.size();}
} }
public boolean isEmpty() { public boolean isEmpty() {
synchronized(mutex) {return c.isEmpty();} synchronized (mutex) {return c.isEmpty();}
} }
public boolean contains(Object o) { public boolean contains(Object o) {
synchronized(mutex) {return c.contains(o);} synchronized (mutex) {return c.contains(o);}
} }
public Object[] toArray() { public Object[] toArray() {
synchronized(mutex) {return c.toArray();} synchronized (mutex) {return c.toArray();}
} }
public <T> T[] toArray(T[] a) { public <T> T[] toArray(T[] a) {
synchronized(mutex) {return c.toArray(a);} synchronized (mutex) {return c.toArray(a);}
} }
public Iterator<E> iterator() { public Iterator<E> iterator() {
...@@ -1631,32 +1631,32 @@ public class Collections { ...@@ -1631,32 +1631,32 @@ public class Collections {
} }
public boolean add(E e) { public boolean add(E e) {
synchronized(mutex) {return c.add(e);} synchronized (mutex) {return c.add(e);}
} }
public boolean remove(Object o) { public boolean remove(Object o) {
synchronized(mutex) {return c.remove(o);} synchronized (mutex) {return c.remove(o);}
} }
public boolean containsAll(Collection<?> coll) { public boolean containsAll(Collection<?> coll) {
synchronized(mutex) {return c.containsAll(coll);} synchronized (mutex) {return c.containsAll(coll);}
} }
public boolean addAll(Collection<? extends E> coll) { public boolean addAll(Collection<? extends E> coll) {
synchronized(mutex) {return c.addAll(coll);} synchronized (mutex) {return c.addAll(coll);}
} }
public boolean removeAll(Collection<?> coll) { public boolean removeAll(Collection<?> coll) {
synchronized(mutex) {return c.removeAll(coll);} synchronized (mutex) {return c.removeAll(coll);}
} }
public boolean retainAll(Collection<?> coll) { public boolean retainAll(Collection<?> coll) {
synchronized(mutex) {return c.retainAll(coll);} synchronized (mutex) {return c.retainAll(coll);}
} }
public void clear() { public void clear() {
synchronized(mutex) {c.clear();} synchronized (mutex) {c.clear();}
} }
public String toString() { public String toString() {
synchronized(mutex) {return c.toString();} synchronized (mutex) {return c.toString();}
} }
private void writeObject(ObjectOutputStream s) throws IOException { private void writeObject(ObjectOutputStream s) throws IOException {
synchronized(mutex) {s.defaultWriteObject();} synchronized (mutex) {s.defaultWriteObject();}
} }
} }
...@@ -1671,7 +1671,7 @@ public class Collections { ...@@ -1671,7 +1671,7 @@ public class Collections {
* <pre> * <pre>
* Set s = Collections.synchronizedSet(new HashSet()); * Set s = Collections.synchronizedSet(new HashSet());
* ... * ...
* synchronized(s) { * synchronized (s) {
* Iterator i = s.iterator(); // Must be in the synchronized block * Iterator i = s.iterator(); // Must be in the synchronized block
* while (i.hasNext()) * while (i.hasNext())
* foo(i.next()); * foo(i.next());
...@@ -1709,10 +1709,10 @@ public class Collections { ...@@ -1709,10 +1709,10 @@ public class Collections {
} }
public boolean equals(Object o) { public boolean equals(Object o) {
synchronized(mutex) {return c.equals(o);} synchronized (mutex) {return c.equals(o);}
} }
public int hashCode() { public int hashCode() {
synchronized(mutex) {return c.hashCode();} synchronized (mutex) {return c.hashCode();}
} }
} }
...@@ -1728,7 +1728,7 @@ public class Collections { ...@@ -1728,7 +1728,7 @@ public class Collections {
* <pre> * <pre>
* SortedSet s = Collections.synchronizedSortedSet(new TreeSet()); * SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
* ... * ...
* synchronized(s) { * synchronized (s) {
* Iterator i = s.iterator(); // Must be in the synchronized block * Iterator i = s.iterator(); // Must be in the synchronized block
* while (i.hasNext()) * while (i.hasNext())
* foo(i.next()); * foo(i.next());
...@@ -1739,7 +1739,7 @@ public class Collections { ...@@ -1739,7 +1739,7 @@ public class Collections {
* SortedSet s = Collections.synchronizedSortedSet(new TreeSet()); * SortedSet s = Collections.synchronizedSortedSet(new TreeSet());
* SortedSet s2 = s.headSet(foo); * SortedSet s2 = s.headSet(foo);
* ... * ...
* synchronized(s) { // Note: s, not s2!!! * synchronized (s) { // Note: s, not s2!!!
* Iterator i = s2.iterator(); // Must be in the synchronized block * Iterator i = s2.iterator(); // Must be in the synchronized block
* while (i.hasNext()) * while (i.hasNext())
* foo(i.next()); * foo(i.next());
...@@ -1766,7 +1766,7 @@ public class Collections { ...@@ -1766,7 +1766,7 @@ public class Collections {
{ {
private static final long serialVersionUID = 8695801310862127406L; private static final long serialVersionUID = 8695801310862127406L;
final private SortedSet<E> ss; private final SortedSet<E> ss;
SynchronizedSortedSet(SortedSet<E> s) { SynchronizedSortedSet(SortedSet<E> s) {
super(s); super(s);
...@@ -1778,31 +1778,31 @@ public class Collections { ...@@ -1778,31 +1778,31 @@ public class Collections {
} }
public Comparator<? super E> comparator() { public Comparator<? super E> comparator() {
synchronized(mutex) {return ss.comparator();} synchronized (mutex) {return ss.comparator();}
} }
public SortedSet<E> subSet(E fromElement, E toElement) { public SortedSet<E> subSet(E fromElement, E toElement) {
synchronized(mutex) { synchronized (mutex) {
return new SynchronizedSortedSet<E>( return new SynchronizedSortedSet<E>(
ss.subSet(fromElement, toElement), mutex); ss.subSet(fromElement, toElement), mutex);
} }
} }
public SortedSet<E> headSet(E toElement) { public SortedSet<E> headSet(E toElement) {
synchronized(mutex) { synchronized (mutex) {
return new SynchronizedSortedSet<E>(ss.headSet(toElement), mutex); return new SynchronizedSortedSet<E>(ss.headSet(toElement), mutex);
} }
} }
public SortedSet<E> tailSet(E fromElement) { public SortedSet<E> tailSet(E fromElement) {
synchronized(mutex) { synchronized (mutex) {
return new SynchronizedSortedSet<E>(ss.tailSet(fromElement),mutex); return new SynchronizedSortedSet<E>(ss.tailSet(fromElement),mutex);
} }
} }
public E first() { public E first() {
synchronized(mutex) {return ss.first();} synchronized (mutex) {return ss.first();}
} }
public E last() { public E last() {
synchronized(mutex) {return ss.last();} synchronized (mutex) {return ss.last();}
} }
} }
...@@ -1817,7 +1817,7 @@ public class Collections { ...@@ -1817,7 +1817,7 @@ public class Collections {
* <pre> * <pre>
* List list = Collections.synchronizedList(new ArrayList()); * List list = Collections.synchronizedList(new ArrayList());
* ... * ...
* synchronized(list) { * synchronized (list) {
* Iterator i = list.iterator(); // Must be in synchronized block * Iterator i = list.iterator(); // Must be in synchronized block
* while (i.hasNext()) * while (i.hasNext())
* foo(i.next()); * foo(i.next());
...@@ -1863,34 +1863,34 @@ public class Collections { ...@@ -1863,34 +1863,34 @@ public class Collections {
} }
public boolean equals(Object o) { public boolean equals(Object o) {
synchronized(mutex) {return list.equals(o);} synchronized (mutex) {return list.equals(o);}
} }
public int hashCode() { public int hashCode() {
synchronized(mutex) {return list.hashCode();} synchronized (mutex) {return list.hashCode();}
} }
public E get(int index) { public E get(int index) {
synchronized(mutex) {return list.get(index);} synchronized (mutex) {return list.get(index);}
} }
public E set(int index, E element) { public E set(int index, E element) {
synchronized(mutex) {return list.set(index, element);} synchronized (mutex) {return list.set(index, element);}
} }
public void add(int index, E element) { public void add(int index, E element) {
synchronized(mutex) {list.add(index, element);} synchronized (mutex) {list.add(index, element);}
} }
public E remove(int index) { public E remove(int index) {
synchronized(mutex) {return list.remove(index);} synchronized (mutex) {return list.remove(index);}
} }
public int indexOf(Object o) { public int indexOf(Object o) {
synchronized(mutex) {return list.indexOf(o);} synchronized (mutex) {return list.indexOf(o);}
} }
public int lastIndexOf(Object o) { public int lastIndexOf(Object o) {
synchronized(mutex) {return list.lastIndexOf(o);} synchronized (mutex) {return list.lastIndexOf(o);}
} }
public boolean addAll(int index, Collection<? extends E> c) { public boolean addAll(int index, Collection<? extends E> c) {
synchronized(mutex) {return list.addAll(index, c);} synchronized (mutex) {return list.addAll(index, c);}
} }
public ListIterator<E> listIterator() { public ListIterator<E> listIterator() {
...@@ -1902,7 +1902,7 @@ public class Collections { ...@@ -1902,7 +1902,7 @@ public class Collections {
} }
public List<E> subList(int fromIndex, int toIndex) { public List<E> subList(int fromIndex, int toIndex) {
synchronized(mutex) { synchronized (mutex) {
return new SynchronizedList<E>(list.subList(fromIndex, toIndex), return new SynchronizedList<E>(list.subList(fromIndex, toIndex),
mutex); mutex);
} }
...@@ -1943,7 +1943,7 @@ public class Collections { ...@@ -1943,7 +1943,7 @@ public class Collections {
} }
public List<E> subList(int fromIndex, int toIndex) { public List<E> subList(int fromIndex, int toIndex) {
synchronized(mutex) { synchronized (mutex) {
return new SynchronizedRandomAccessList<E>( return new SynchronizedRandomAccessList<E>(
list.subList(fromIndex, toIndex), mutex); list.subList(fromIndex, toIndex), mutex);
} }
...@@ -1975,7 +1975,7 @@ public class Collections { ...@@ -1975,7 +1975,7 @@ public class Collections {
* ... * ...
* Set s = m.keySet(); // Needn't be in synchronized block * Set s = m.keySet(); // Needn't be in synchronized block
* ... * ...
* synchronized(m) { // Synchronizing on m, not s! * synchronized (m) { // Synchronizing on m, not s!
* Iterator i = s.iterator(); // Must be in synchronized block * Iterator i = s.iterator(); // Must be in synchronized block
* while (i.hasNext()) * while (i.hasNext())
* foo(i.next()); * foo(i.next());
...@@ -2016,32 +2016,32 @@ public class Collections { ...@@ -2016,32 +2016,32 @@ public class Collections {
} }
public int size() { public int size() {
synchronized(mutex) {return m.size();} synchronized (mutex) {return m.size();}
} }
public boolean isEmpty() { public boolean isEmpty() {
synchronized(mutex) {return m.isEmpty();} synchronized (mutex) {return m.isEmpty();}
} }
public boolean containsKey(Object key) { public boolean containsKey(Object key) {
synchronized(mutex) {return m.containsKey(key);} synchronized (mutex) {return m.containsKey(key);}
} }
public boolean containsValue(Object value) { public boolean containsValue(Object value) {
synchronized(mutex) {return m.containsValue(value);} synchronized (mutex) {return m.containsValue(value);}
} }
public V get(Object key) { public V get(Object key) {
synchronized(mutex) {return m.get(key);} synchronized (mutex) {return m.get(key);}
} }
public V put(K key, V value) { public V put(K key, V value) {
synchronized(mutex) {return m.put(key, value);} synchronized (mutex) {return m.put(key, value);}
} }
public V remove(Object key) { public V remove(Object key) {
synchronized(mutex) {return m.remove(key);} synchronized (mutex) {return m.remove(key);}
} }
public void putAll(Map<? extends K, ? extends V> map) { public void putAll(Map<? extends K, ? extends V> map) {
synchronized(mutex) {m.putAll(map);} synchronized (mutex) {m.putAll(map);}
} }
public void clear() { public void clear() {
synchronized(mutex) {m.clear();} synchronized (mutex) {m.clear();}
} }
private transient Set<K> keySet = null; private transient Set<K> keySet = null;
...@@ -2049,7 +2049,7 @@ public class Collections { ...@@ -2049,7 +2049,7 @@ public class Collections {
private transient Collection<V> values = null; private transient Collection<V> values = null;
public Set<K> keySet() { public Set<K> keySet() {
synchronized(mutex) { synchronized (mutex) {
if (keySet==null) if (keySet==null)
keySet = new SynchronizedSet<K>(m.keySet(), mutex); keySet = new SynchronizedSet<K>(m.keySet(), mutex);
return keySet; return keySet;
...@@ -2057,7 +2057,7 @@ public class Collections { ...@@ -2057,7 +2057,7 @@ public class Collections {
} }
public Set<Map.Entry<K,V>> entrySet() { public Set<Map.Entry<K,V>> entrySet() {
synchronized(mutex) { synchronized (mutex) {
if (entrySet==null) if (entrySet==null)
entrySet = new SynchronizedSet<Map.Entry<K,V>>(m.entrySet(), mutex); entrySet = new SynchronizedSet<Map.Entry<K,V>>(m.entrySet(), mutex);
return entrySet; return entrySet;
...@@ -2065,7 +2065,7 @@ public class Collections { ...@@ -2065,7 +2065,7 @@ public class Collections {
} }
public Collection<V> values() { public Collection<V> values() {
synchronized(mutex) { synchronized (mutex) {
if (values==null) if (values==null)
values = new SynchronizedCollection<V>(m.values(), mutex); values = new SynchronizedCollection<V>(m.values(), mutex);
return values; return values;
...@@ -2073,16 +2073,16 @@ public class Collections { ...@@ -2073,16 +2073,16 @@ public class Collections {
} }
public boolean equals(Object o) { public boolean equals(Object o) {
synchronized(mutex) {return m.equals(o);} synchronized (mutex) {return m.equals(o);}
} }
public int hashCode() { public int hashCode() {
synchronized(mutex) {return m.hashCode();} synchronized (mutex) {return m.hashCode();}
} }
public String toString() { public String toString() {
synchronized(mutex) {return m.toString();} synchronized (mutex) {return m.toString();}
} }
private void writeObject(ObjectOutputStream s) throws IOException { private void writeObject(ObjectOutputStream s) throws IOException {
synchronized(mutex) {s.defaultWriteObject();} synchronized (mutex) {s.defaultWriteObject();}
} }
} }
...@@ -2101,7 +2101,7 @@ public class Collections { ...@@ -2101,7 +2101,7 @@ public class Collections {
* ... * ...
* Set s = m.keySet(); // Needn't be in synchronized block * Set s = m.keySet(); // Needn't be in synchronized block
* ... * ...
* synchronized(m) { // Synchronizing on m, not s! * synchronized (m) { // Synchronizing on m, not s!
* Iterator i = s.iterator(); // Must be in synchronized block * Iterator i = s.iterator(); // Must be in synchronized block
* while (i.hasNext()) * while (i.hasNext())
* foo(i.next()); * foo(i.next());
...@@ -2114,7 +2114,7 @@ public class Collections { ...@@ -2114,7 +2114,7 @@ public class Collections {
* ... * ...
* Set s2 = m2.keySet(); // Needn't be in synchronized block * Set s2 = m2.keySet(); // Needn't be in synchronized block
* ... * ...
* synchronized(m) { // Synchronizing on m, not m2 or s2! * synchronized (m) { // Synchronizing on m, not m2 or s2!
* Iterator i = s.iterator(); // Must be in synchronized block * Iterator i = s.iterator(); // Must be in synchronized block
* while (i.hasNext()) * while (i.hasNext())
* foo(i.next()); * foo(i.next());
...@@ -2154,31 +2154,31 @@ public class Collections { ...@@ -2154,31 +2154,31 @@ public class Collections {
} }
public Comparator<? super K> comparator() { public Comparator<? super K> comparator() {
synchronized(mutex) {return sm.comparator();} synchronized (mutex) {return sm.comparator();}
} }
public SortedMap<K,V> subMap(K fromKey, K toKey) { public SortedMap<K,V> subMap(K fromKey, K toKey) {
synchronized(mutex) { synchronized (mutex) {
return new SynchronizedSortedMap<K,V>( return new SynchronizedSortedMap<K,V>(
sm.subMap(fromKey, toKey), mutex); sm.subMap(fromKey, toKey), mutex);
} }
} }
public SortedMap<K,V> headMap(K toKey) { public SortedMap<K,V> headMap(K toKey) {
synchronized(mutex) { synchronized (mutex) {
return new SynchronizedSortedMap<K,V>(sm.headMap(toKey), mutex); return new SynchronizedSortedMap<K,V>(sm.headMap(toKey), mutex);
} }
} }
public SortedMap<K,V> tailMap(K fromKey) { public SortedMap<K,V> tailMap(K fromKey) {
synchronized(mutex) { synchronized (mutex) {
return new SynchronizedSortedMap<K,V>(sm.tailMap(fromKey),mutex); return new SynchronizedSortedMap<K,V>(sm.tailMap(fromKey),mutex);
} }
} }
public K firstKey() { public K firstKey() {
synchronized(mutex) {return sm.firstKey();} synchronized (mutex) {return sm.firstKey();}
} }
public K lastKey() { public K lastKey() {
synchronized(mutex) {return sm.lastKey();} synchronized (mutex) {return sm.lastKey();}
} }
} }
...@@ -3317,7 +3317,7 @@ public class Collections { ...@@ -3317,7 +3317,7 @@ public class Collections {
{ {
private static final long serialVersionUID = 3193687207550431679L; private static final long serialVersionUID = 3193687207550431679L;
final private E element; private final E element;
SingletonSet(E e) {element = e;} SingletonSet(E e) {element = e;}
...@@ -3448,7 +3448,7 @@ public class Collections { ...@@ -3448,7 +3448,7 @@ public class Collections {
* @param o the element to appear repeatedly in the returned list. * @param o the element to appear repeatedly in the returned list.
* @return an immutable list consisting of <tt>n</tt> copies of the * @return an immutable list consisting of <tt>n</tt> copies of the
* specified object. * specified object.
* @throws IllegalArgumentException if n &lt; 0. * @throws IllegalArgumentException if {@code n < 0}
* @see List#addAll(Collection) * @see List#addAll(Collection)
* @see List#addAll(int, Collection) * @see List#addAll(int, Collection)
*/ */
......
...@@ -207,7 +207,7 @@ class ComparableTimSort { ...@@ -207,7 +207,7 @@ class ComparableTimSort {
* @param lo the index of the first element in the range to be sorted * @param lo the index of the first element in the range to be sorted
* @param hi the index after the last element in the range to be sorted * @param hi the index after the last element in the range to be sorted
* @param start the index of the first element in the range that is * @param start the index of the first element in the range that is
* not already known to be sorted (@code lo <= start <= hi} * not already known to be sorted ({@code lo <= start <= hi})
*/ */
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
private static void binarySort(Object[] a, int lo, int hi, int start) { private static void binarySort(Object[] a, int lo, int hi, int start) {
...@@ -245,7 +245,7 @@ class ComparableTimSort { ...@@ -245,7 +245,7 @@ class ComparableTimSort {
*/ */
int n = start - left; // The number of elements to move int n = start - left; // The number of elements to move
// Switch is just an optimization for arraycopy in default case // Switch is just an optimization for arraycopy in default case
switch(n) { switch (n) {
case 2: a[left + 2] = a[left + 1]; case 2: a[left + 2] = a[left + 1];
case 1: a[left + 1] = a[left]; case 1: a[left + 1] = a[left];
break; break;
...@@ -275,7 +275,7 @@ class ComparableTimSort { ...@@ -275,7 +275,7 @@ class ComparableTimSort {
* @param a the array in which a run is to be counted and possibly reversed * @param a the array in which a run is to be counted and possibly reversed
* @param lo index of the first element in the run * @param lo index of the first element in the run
* @param hi index after the last element that may be contained in the run. * @param hi index after the last element that may be contained in the run.
It is required that @code{lo < hi}. It is required that {@code lo < hi}.
* @return the length of the run beginning at the specified position in * @return the length of the run beginning at the specified position in
* the specified array * the specified array
*/ */
...@@ -288,7 +288,7 @@ class ComparableTimSort { ...@@ -288,7 +288,7 @@ class ComparableTimSort {
// Find end of run, and reverse range if descending // Find end of run, and reverse range if descending
if (((Comparable) a[runHi++]).compareTo(a[lo]) < 0) { // Descending if (((Comparable) a[runHi++]).compareTo(a[lo]) < 0) { // Descending
while(runHi < hi && ((Comparable) a[runHi]).compareTo(a[runHi - 1]) < 0) while (runHi < hi && ((Comparable) a[runHi]).compareTo(a[runHi - 1]) < 0)
runHi++; runHi++;
reverseRange(a, lo, runHi); reverseRange(a, lo, runHi);
} else { // Ascending } else { // Ascending
......
...@@ -77,9 +77,9 @@ class Random implements java.io.Serializable { ...@@ -77,9 +77,9 @@ class Random implements java.io.Serializable {
*/ */
private final AtomicLong seed; private final AtomicLong seed;
private final static long multiplier = 0x5DEECE66DL; private static final long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL; private static final long addend = 0xBL;
private final static long mask = (1L << 48) - 1; private static final long mask = (1L << 48) - 1;
/** /**
* Creates a new random number generator. This constructor sets * Creates a new random number generator. This constructor sets
...@@ -285,7 +285,7 @@ class Random implements java.io.Serializable { ...@@ -285,7 +285,7 @@ class Random implements java.io.Serializable {
* @return the next pseudorandom, uniformly distributed {@code int} * @return the next pseudorandom, uniformly distributed {@code int}
* value between {@code 0} (inclusive) and {@code n} (exclusive) * value between {@code 0} (inclusive) and {@code n} (exclusive)
* from this random number generator's sequence * from this random number generator's sequence
* @exception IllegalArgumentException if n is not positive * @throws IllegalArgumentException if n is not positive
* @since 1.2 * @since 1.2
*/ */
......
...@@ -73,9 +73,9 @@ class Stack<E> extends Vector<E> { ...@@ -73,9 +73,9 @@ class Stack<E> extends Vector<E> {
* Removes the object at the top of this stack and returns that * Removes the object at the top of this stack and returns that
* object as the value of this function. * object as the value of this function.
* *
* @return The object at the top of this stack (the last item * @return The object at the top of this stack (the last item
* of the <tt>Vector</tt> object). * of the <tt>Vector</tt> object).
* @exception EmptyStackException if this stack is empty. * @throws EmptyStackException if this stack is empty.
*/ */
public synchronized E pop() { public synchronized E pop() {
E obj; E obj;
...@@ -91,9 +91,9 @@ class Stack<E> extends Vector<E> { ...@@ -91,9 +91,9 @@ class Stack<E> extends Vector<E> {
* Looks at the object at the top of this stack without removing it * Looks at the object at the top of this stack without removing it
* from the stack. * from the stack.
* *
* @return the object at the top of this stack (the last item * @return the object at the top of this stack (the last item
* of the <tt>Vector</tt> object). * of the <tt>Vector</tt> object).
* @exception EmptyStackException if this stack is empty. * @throws EmptyStackException if this stack is empty.
*/ */
public synchronized E peek() { public synchronized E peek() {
int len = size(); int len = size();
......
...@@ -239,7 +239,7 @@ class TimSort<T> { ...@@ -239,7 +239,7 @@ class TimSort<T> {
* @param lo the index of the first element in the range to be sorted * @param lo the index of the first element in the range to be sorted
* @param hi the index after the last element in the range to be sorted * @param hi the index after the last element in the range to be sorted
* @param start the index of the first element in the range that is * @param start the index of the first element in the range that is
* not already known to be sorted (@code lo <= start <= hi} * not already known to be sorted ({@code lo <= start <= hi})
* @param c comparator to used for the sort * @param c comparator to used for the sort
*/ */
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
...@@ -278,7 +278,7 @@ class TimSort<T> { ...@@ -278,7 +278,7 @@ class TimSort<T> {
*/ */
int n = start - left; // The number of elements to move int n = start - left; // The number of elements to move
// Switch is just an optimization for arraycopy in default case // Switch is just an optimization for arraycopy in default case
switch(n) { switch (n) {
case 2: a[left + 2] = a[left + 1]; case 2: a[left + 2] = a[left + 1];
case 1: a[left + 1] = a[left]; case 1: a[left + 1] = a[left];
break; break;
...@@ -308,7 +308,7 @@ class TimSort<T> { ...@@ -308,7 +308,7 @@ class TimSort<T> {
* @param a the array in which a run is to be counted and possibly reversed * @param a the array in which a run is to be counted and possibly reversed
* @param lo index of the first element in the run * @param lo index of the first element in the run
* @param hi index after the last element that may be contained in the run. * @param hi index after the last element that may be contained in the run.
It is required that @code{lo < hi}. It is required that {@code lo < hi}.
* @param c the comparator to used for the sort * @param c the comparator to used for the sort
* @return the length of the run beginning at the specified position in * @return the length of the run beginning at the specified position in
* the specified array * the specified array
...@@ -322,7 +322,7 @@ class TimSort<T> { ...@@ -322,7 +322,7 @@ class TimSort<T> {
// Find end of run, and reverse range if descending // Find end of run, and reverse range if descending
if (c.compare(a[runHi++], a[lo]) < 0) { // Descending if (c.compare(a[runHi++], a[lo]) < 0) { // Descending
while(runHi < hi && c.compare(a[runHi], a[runHi - 1]) < 0) while (runHi < hi && c.compare(a[runHi], a[runHi - 1]) < 0)
runHi++; runHi++;
reverseRange(a, lo, runHi); reverseRange(a, lo, runHi);
} else { // Ascending } else { // Ascending
......
...@@ -1056,11 +1056,11 @@ public class TreeMap<K,V> ...@@ -1056,11 +1056,11 @@ public class TreeMap<K,V>
public Comparator<? super E> comparator() { return m.comparator(); } public Comparator<? super E> comparator() { return m.comparator(); }
public E pollFirst() { public E pollFirst() {
Map.Entry<E,Object> e = m.pollFirstEntry(); Map.Entry<E,Object> e = m.pollFirstEntry();
return e == null? null : e.getKey(); return (e == null) ? null : e.getKey();
} }
public E pollLast() { public E pollLast() {
Map.Entry<E,Object> e = m.pollLastEntry(); Map.Entry<E,Object> e = m.pollLastEntry();
return e == null? null : e.getKey(); return (e == null) ? null : e.getKey();
} }
public boolean remove(Object o) { public boolean remove(Object o) {
int oldSize = size(); int oldSize = size();
...@@ -1196,7 +1196,7 @@ public class TreeMap<K,V> ...@@ -1196,7 +1196,7 @@ public class TreeMap<K,V>
* Test two values for equality. Differs from o1.equals(o2) only in * Test two values for equality. Differs from o1.equals(o2) only in
* that it copes with {@code null} o1 properly. * that it copes with {@code null} o1 properly.
*/ */
final static boolean valEquals(Object o1, Object o2) { static final boolean valEquals(Object o1, Object o2) {
return (o1==null ? o2==null : o1.equals(o2)); return (o1==null ? o2==null : o1.equals(o2));
} }
...@@ -1204,7 +1204,7 @@ public class TreeMap<K,V> ...@@ -1204,7 +1204,7 @@ public class TreeMap<K,V>
* Return SimpleImmutableEntry for entry, or null if null * Return SimpleImmutableEntry for entry, or null if null
*/ */
static <K,V> Map.Entry<K,V> exportEntry(TreeMap.Entry<K,V> e) { static <K,V> Map.Entry<K,V> exportEntry(TreeMap.Entry<K,V> e) {
return e == null? null : return (e == null) ? null :
new AbstractMap.SimpleImmutableEntry<K,V>(e); new AbstractMap.SimpleImmutableEntry<K,V>(e);
} }
...@@ -1212,7 +1212,7 @@ public class TreeMap<K,V> ...@@ -1212,7 +1212,7 @@ public class TreeMap<K,V>
* Return key for entry, or null if null * Return key for entry, or null if null
*/ */
static <K,V> K keyOrNull(TreeMap.Entry<K,V> e) { static <K,V> K keyOrNull(TreeMap.Entry<K,V> e) {
return e == null? null : e.key; return (e == null) ? null : e.key;
} }
/** /**
...@@ -1237,7 +1237,7 @@ public class TreeMap<K,V> ...@@ -1237,7 +1237,7 @@ public class TreeMap<K,V>
/** /**
* @serial include * @serial include
*/ */
static abstract class NavigableSubMap<K,V> extends AbstractMap<K,V> abstract static class NavigableSubMap<K,V> extends AbstractMap<K,V>
implements NavigableMap<K,V>, java.io.Serializable { implements NavigableMap<K,V>, java.io.Serializable {
/** /**
* The backing map. * The backing map.
...@@ -1412,11 +1412,11 @@ public class TreeMap<K,V> ...@@ -1412,11 +1412,11 @@ public class TreeMap<K,V>
} }
public final V get(Object key) { public final V get(Object key) {
return !inRange(key)? null : m.get(key); return !inRange(key) ? null : m.get(key);
} }
public final V remove(Object key) { public final V remove(Object key) {
return !inRange(key)? null : m.remove(key); return !inRange(key) ? null : m.remove(key);
} }
public final Map.Entry<K,V> ceilingEntry(K key) { public final Map.Entry<K,V> ceilingEntry(K key) {
...@@ -1559,7 +1559,8 @@ public class TreeMap<K,V> ...@@ -1559,7 +1559,8 @@ public class TreeMap<K,V>
if (!inRange(key)) if (!inRange(key))
return false; return false;
TreeMap.Entry<K,V> node = m.getEntry(key); TreeMap.Entry<K,V> node = m.getEntry(key);
if (node!=null && valEquals(node.getValue(),entry.getValue())){ if (node!=null && valEquals(node.getValue(),
entry.getValue())) {
m.deleteEntry(node); m.deleteEntry(node);
return true; return true;
} }
...@@ -1724,7 +1725,7 @@ public class TreeMap<K,V> ...@@ -1724,7 +1725,7 @@ public class TreeMap<K,V>
false, toKey, inclusive); false, toKey, inclusive);
} }
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive){ public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
if (!inRange(fromKey, inclusive)) if (!inRange(fromKey, inclusive))
throw new IllegalArgumentException("fromKey out of range"); throw new IllegalArgumentException("fromKey out of range");
return new AscendingSubMap(m, return new AscendingSubMap(m,
...@@ -1805,7 +1806,7 @@ public class TreeMap<K,V> ...@@ -1805,7 +1806,7 @@ public class TreeMap<K,V>
toEnd, hi, hiInclusive); toEnd, hi, hiInclusive);
} }
public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive){ public NavigableMap<K,V> tailMap(K fromKey, boolean inclusive) {
if (!inRange(fromKey, inclusive)) if (!inRange(fromKey, inclusive))
throw new IllegalArgumentException("fromKey out of range"); throw new IllegalArgumentException("fromKey out of range");
return new DescendingSubMap(m, return new DescendingSubMap(m,
...@@ -2143,7 +2144,7 @@ public class TreeMap<K,V> ...@@ -2143,7 +2144,7 @@ public class TreeMap<K,V>
// If strictly internal, copy successor's element to p and then make p // If strictly internal, copy successor's element to p and then make p
// point to successor. // point to successor.
if (p.left != null && p.right != null) { if (p.left != null && p.right != null) {
Entry<K,V> s = successor (p); Entry<K,V> s = successor(p);
p.key = s.key; p.key = s.key;
p.value = s.value; p.value = s.value;
p = s; p = s;
......
...@@ -452,7 +452,7 @@ public class TreeSet<E> extends AbstractSet<E> ...@@ -452,7 +452,7 @@ public class TreeSet<E> extends AbstractSet<E>
*/ */
public E pollFirst() { public E pollFirst() {
Map.Entry<E,?> e = m.pollFirstEntry(); Map.Entry<E,?> e = m.pollFirstEntry();
return (e == null)? null : e.getKey(); return (e == null) ? null : e.getKey();
} }
/** /**
...@@ -460,7 +460,7 @@ public class TreeSet<E> extends AbstractSet<E> ...@@ -460,7 +460,7 @@ public class TreeSet<E> extends AbstractSet<E>
*/ */
public E pollLast() { public E pollLast() {
Map.Entry<E,?> e = m.pollLastEntry(); Map.Entry<E,?> e = m.pollLastEntry();
return (e == null)? null : e.getKey(); return (e == null) ? null : e.getKey();
} }
/** /**
......
...@@ -919,7 +919,7 @@ public class Vector<E> ...@@ -919,7 +919,7 @@ public class Vector<E>
* elements (optional), or if the specified collection is null * elements (optional), or if the specified collection is null
* @since 1.2 * @since 1.2
*/ */
public synchronized boolean retainAll(Collection<?> c) { public synchronized boolean retainAll(Collection<?> c) {
return super.retainAll(c); return super.retainAll(c);
} }
......
...@@ -51,20 +51,20 @@ import java.util.*; ...@@ -51,20 +51,20 @@ import java.util.*;
* <p> <b>Extension example</b>. Here is a sketch of a class * <p> <b>Extension example</b>. Here is a sketch of a class
* that customizes {@link ThreadPoolExecutor} to use * that customizes {@link ThreadPoolExecutor} to use
* a <tt>CustomTask</tt> class instead of the default <tt>FutureTask</tt>: * a <tt>CustomTask</tt> class instead of the default <tt>FutureTask</tt>:
* <pre> * <pre> {@code
* public class CustomThreadPoolExecutor extends ThreadPoolExecutor { * public class CustomThreadPoolExecutor extends ThreadPoolExecutor {
* *
* static class CustomTask&lt;V&gt; implements RunnableFuture&lt;V&gt; {...} * static class CustomTask<V> implements RunnableFuture<V> {...}
* *
* protected &lt;V&gt; RunnableFuture&lt;V&gt; newTaskFor(Callable&lt;V&gt; c) { * protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) {
* return new CustomTask&lt;V&gt;(c); * return new CustomTask<V>(c);
* } * }
* protected &lt;V&gt; RunnableFuture&lt;V&gt; newTaskFor(Runnable r, V v) { * protected <V> RunnableFuture<V> newTaskFor(Runnable r, V v) {
* return new CustomTask&lt;V&gt;(r, v); * return new CustomTask<V>(r, v);
* } * }
* // ... add constructors, etc. * // ... add constructors, etc.
* } * }}</pre>
* </pre> *
* @since 1.5 * @since 1.5
* @author Doug Lea * @author Doug Lea
*/ */
...@@ -106,7 +106,7 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -106,7 +106,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
*/ */
public Future<?> submit(Runnable task) { public Future<?> submit(Runnable task) {
if (task == null) throw new NullPointerException(); if (task == null) throw new NullPointerException();
RunnableFuture<Object> ftask = newTaskFor(task, null); RunnableFuture<Void> ftask = newTaskFor(task, null);
execute(ftask); execute(ftask);
return ftask; return ftask;
} }
...@@ -158,7 +158,7 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -158,7 +158,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
// Record exceptions so that if we fail to obtain any // Record exceptions so that if we fail to obtain any
// result, we can throw the last exception we got. // result, we can throw the last exception we got.
ExecutionException ee = null; ExecutionException ee = null;
long lastTime = (timed)? System.nanoTime() : 0; long lastTime = timed ? System.nanoTime() : 0;
Iterator<? extends Callable<T>> it = tasks.iterator(); Iterator<? extends Callable<T>> it = tasks.iterator();
// Start one task for sure; the rest incrementally // Start one task for sure; the rest incrementally
...@@ -191,8 +191,6 @@ public abstract class AbstractExecutorService implements ExecutorService { ...@@ -191,8 +191,6 @@ public abstract class AbstractExecutorService implements ExecutorService {
--active; --active;
try { try {
return f.get(); return f.get();
} catch (InterruptedException ie) {
throw ie;
} catch (ExecutionException eex) { } catch (ExecutionException eex) {
ee = eex; ee = eex;
} catch (RuntimeException rex) { } catch (RuntimeException rex) {
......
...@@ -1270,7 +1270,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> ...@@ -1270,7 +1270,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V>
* for each key-value mapping, followed by a null pair. * for each key-value mapping, followed by a null pair.
* The key-value mappings are emitted in no particular order. * The key-value mappings are emitted in no particular order.
*/ */
private void writeObject(java.io.ObjectOutputStream s) throws IOException { private void writeObject(java.io.ObjectOutputStream s) throws IOException {
s.defaultWriteObject(); s.defaultWriteObject();
for (int k = 0; k < segments.length; ++k) { for (int k = 0; k < segments.length; ++k) {
...@@ -1298,7 +1298,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> ...@@ -1298,7 +1298,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V>
* @param s the stream * @param s the stream
*/ */
private void readObject(java.io.ObjectInputStream s) private void readObject(java.io.ObjectInputStream s)
throws IOException, ClassNotFoundException { throws IOException, ClassNotFoundException {
s.defaultReadObject(); s.defaultReadObject();
// Initialize each segment to be minimally sized, and let grow. // Initialize each segment to be minimally sized, and let grow.
......
...@@ -38,7 +38,6 @@ package java.util.concurrent; ...@@ -38,7 +38,6 @@ package java.util.concurrent;
import java.util.AbstractCollection; import java.util.AbstractCollection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Deque; import java.util.Deque;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
...@@ -212,7 +211,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -212,7 +211,7 @@ public class ConcurrentLinkedDeque<E>
* The actual representation we use is that p.next == p means to * The actual representation we use is that p.next == p means to
* goto the first node (which in turn is reached by following prev * goto the first node (which in turn is reached by following prev
* pointers from head), and p.next == null && p.prev == p means * pointers from head), and p.next == null && p.prev == p means
* that the iteration is at an end and that p is a (final static) * that the iteration is at an end and that p is a (static final)
* dummy node, NEXT_TERMINATOR, and not the last active node. * dummy node, NEXT_TERMINATOR, and not the last active node.
* Finishing the iteration when encountering such a TERMINATOR is * Finishing the iteration when encountering such a TERMINATOR is
* good enough for read-only traversals, so such traversals can use * good enough for read-only traversals, so such traversals can use
...@@ -271,7 +270,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -271,7 +270,7 @@ public class ConcurrentLinkedDeque<E>
*/ */
private transient volatile Node<E> tail; private transient volatile Node<E> tail;
private final static Node<Object> PREV_TERMINATOR, NEXT_TERMINATOR; private static final Node<Object> PREV_TERMINATOR, NEXT_TERMINATOR;
static { static {
PREV_TERMINATOR = new Node<Object>(null); PREV_TERMINATOR = new Node<Object>(null);
...@@ -401,7 +400,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -401,7 +400,7 @@ public class ConcurrentLinkedDeque<E>
} }
} }
private final static int HOPS = 2; private static final int HOPS = 2;
/** /**
* Unlinks non-null node x. * Unlinks non-null node x.
...@@ -871,7 +870,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -871,7 +870,7 @@ public class ConcurrentLinkedDeque<E>
/** /**
* Inserts the specified element at the front of this deque. * Inserts the specified element at the front of this deque.
* *
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException if the specified element is null
*/ */
public void addFirst(E e) { public void addFirst(E e) {
linkFirst(e); linkFirst(e);
...@@ -882,7 +881,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -882,7 +881,7 @@ public class ConcurrentLinkedDeque<E>
* *
* <p>This method is equivalent to {@link #add}. * <p>This method is equivalent to {@link #add}.
* *
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException if the specified element is null
*/ */
public void addLast(E e) { public void addLast(E e) {
linkLast(e); linkLast(e);
...@@ -892,7 +891,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -892,7 +891,7 @@ public class ConcurrentLinkedDeque<E>
* Inserts the specified element at the front of this deque. * Inserts the specified element at the front of this deque.
* *
* @return {@code true} always * @return {@code true} always
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException if the specified element is null
*/ */
public boolean offerFirst(E e) { public boolean offerFirst(E e) {
linkFirst(e); linkFirst(e);
...@@ -905,7 +904,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -905,7 +904,7 @@ public class ConcurrentLinkedDeque<E>
* <p>This method is equivalent to {@link #add}. * <p>This method is equivalent to {@link #add}.
* *
* @return {@code true} always * @return {@code true} always
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException if the specified element is null
*/ */
public boolean offerLast(E e) { public boolean offerLast(E e) {
linkLast(e); linkLast(e);
...@@ -940,7 +939,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -940,7 +939,7 @@ public class ConcurrentLinkedDeque<E>
/** /**
* @throws NoSuchElementException {@inheritDoc} * @throws NoSuchElementException {@inheritDoc}
*/ */
public E getLast() { public E getLast() {
return screenNullResult(peekLast()); return screenNullResult(peekLast());
} }
...@@ -1016,7 +1015,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -1016,7 +1015,7 @@ public class ConcurrentLinkedDeque<E>
* *
* @param o element to be removed from this deque, if present * @param o element to be removed from this deque, if present
* @return {@code true} if the deque contained the specified element * @return {@code true} if the deque contained the specified element
* @throws NullPointerException if the specified element is {@code null} * @throws NullPointerException if the specified element is null
*/ */
public boolean removeFirstOccurrence(Object o) { public boolean removeFirstOccurrence(Object o) {
checkNotNull(o); checkNotNull(o);
...@@ -1037,7 +1036,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -1037,7 +1036,7 @@ public class ConcurrentLinkedDeque<E>
* *
* @param o element to be removed from this deque, if present * @param o element to be removed from this deque, if present
* @return {@code true} if the deque contained the specified element * @return {@code true} if the deque contained the specified element
* @throws NullPointerException if the specified element is {@code null} * @throws NullPointerException if the specified element is null
*/ */
public boolean removeLastOccurrence(Object o) { public boolean removeLastOccurrence(Object o) {
checkNotNull(o); checkNotNull(o);
...@@ -1110,7 +1109,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -1110,7 +1109,7 @@ public class ConcurrentLinkedDeque<E>
* *
* @param o element to be removed from this deque, if present * @param o element to be removed from this deque, if present
* @return {@code true} if the deque contained the specified element * @return {@code true} if the deque contained the specified element
* @throws NullPointerException if the specified element is {@code null} * @throws NullPointerException if the specified element is null
*/ */
public boolean remove(Object o) { public boolean remove(Object o) {
return removeFirstOccurrence(o); return removeFirstOccurrence(o);
...@@ -1165,7 +1164,7 @@ public class ConcurrentLinkedDeque<E> ...@@ -1165,7 +1164,7 @@ public class ConcurrentLinkedDeque<E>
beginningOfTheEnd.lazySetPrev(p); // CAS piggyback beginningOfTheEnd.lazySetPrev(p); // CAS piggyback
if (p.casNext(null, beginningOfTheEnd)) { if (p.casNext(null, beginningOfTheEnd)) {
// Successful CAS is the linearization point // Successful CAS is the linearization point
// for all elements to be added to this queue. // for all elements to be added to this deque.
if (!casTail(t, last)) { if (!casTail(t, last)) {
// Try a little harder to update tail, // Try a little harder to update tail,
// since we may be adding many elements. // since we may be adding many elements.
...@@ -1251,12 +1250,12 @@ public class ConcurrentLinkedDeque<E> ...@@ -1251,12 +1250,12 @@ public class ConcurrentLinkedDeque<E>
* Returns an iterator over the elements in this deque in proper sequence. * Returns an iterator over the elements in this deque in proper sequence.
* The elements will be returned in order from first (head) to last (tail). * The elements will be returned in order from first (head) to last (tail).
* *
* <p>The returned {@code Iterator} is a "weakly consistent" iterator that * <p>The returned iterator is a "weakly consistent" iterator that
* will never throw {@link java.util.ConcurrentModificationException * will never throw {@link java.util.ConcurrentModificationException
* ConcurrentModificationException}, * ConcurrentModificationException}, and guarantees to traverse
* and guarantees to traverse elements as they existed upon * elements as they existed upon construction of the iterator, and
* construction of the iterator, and may (but is not guaranteed to) * may (but is not guaranteed to) reflect any modifications
* reflect any modifications subsequent to construction. * subsequent to construction.
* *
* @return an iterator over the elements in this deque in proper sequence * @return an iterator over the elements in this deque in proper sequence
*/ */
...@@ -1269,12 +1268,12 @@ public class ConcurrentLinkedDeque<E> ...@@ -1269,12 +1268,12 @@ public class ConcurrentLinkedDeque<E>
* sequential order. The elements will be returned in order from * sequential order. The elements will be returned in order from
* last (tail) to first (head). * last (tail) to first (head).
* *
* <p>The returned {@code Iterator} is a "weakly consistent" iterator that * <p>The returned iterator is a "weakly consistent" iterator that
* will never throw {@link java.util.ConcurrentModificationException * will never throw {@link java.util.ConcurrentModificationException
* ConcurrentModificationException}, * ConcurrentModificationException}, and guarantees to traverse
* and guarantees to traverse elements as they existed upon * elements as they existed upon construction of the iterator, and
* construction of the iterator, and may (but is not guaranteed to) * may (but is not guaranteed to) reflect any modifications
* reflect any modifications subsequent to construction. * subsequent to construction.
* *
* @return an iterator over the elements in this deque in reverse order * @return an iterator over the elements in this deque in reverse order
*/ */
......
...@@ -65,8 +65,8 @@ import java.util.Queue; ...@@ -65,8 +65,8 @@ import java.util.Queue;
* <p>Iterators are <i>weakly consistent</i>, returning elements * <p>Iterators are <i>weakly consistent</i>, returning elements
* reflecting the state of the queue at some point at or since the * reflecting the state of the queue at some point at or since the
* creation of the iterator. They do <em>not</em> throw {@link * creation of the iterator. They do <em>not</em> throw {@link
* ConcurrentModificationException}, and may proceed concurrently with * java.util.ConcurrentModificationException}, and may proceed concurrently
* other operations. Elements contained in the queue since the creation * with other operations. Elements contained in the queue since the creation
* of the iterator will be returned exactly once. * of the iterator will be returned exactly once.
* *
* <p>Beware that, unlike in most collections, the {@code size} method * <p>Beware that, unlike in most collections, the {@code size} method
...@@ -634,12 +634,12 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E> ...@@ -634,12 +634,12 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
* Returns an iterator over the elements in this queue in proper sequence. * Returns an iterator over the elements in this queue in proper sequence.
* The elements will be returned in order from first (head) to last (tail). * The elements will be returned in order from first (head) to last (tail).
* *
* <p>The returned {@code Iterator} is a "weakly consistent" iterator that * <p>The returned iterator is a "weakly consistent" iterator that
* will never throw {@link java.util.ConcurrentModificationException * will never throw {@link java.util.ConcurrentModificationException
* ConcurrentModificationException}, * ConcurrentModificationException}, and guarantees to traverse
* and guarantees to traverse elements as they existed upon * elements as they existed upon construction of the iterator, and
* construction of the iterator, and may (but is not guaranteed to) * may (but is not guaranteed to) reflect any modifications
* reflect any modifications subsequent to construction. * subsequent to construction.
* *
* @return an iterator over the elements in this queue in proper sequence * @return an iterator over the elements in this queue in proper sequence
*/ */
......
...@@ -362,12 +362,12 @@ public class ConcurrentSkipListSet<E> ...@@ -362,12 +362,12 @@ public class ConcurrentSkipListSet<E>
public E pollFirst() { public E pollFirst() {
Map.Entry<E,Object> e = m.pollFirstEntry(); Map.Entry<E,Object> e = m.pollFirstEntry();
return e == null? null : e.getKey(); return (e == null) ? null : e.getKey();
} }
public E pollLast() { public E pollLast() {
Map.Entry<E,Object> e = m.pollLastEntry(); Map.Entry<E,Object> e = m.pollLastEntry();
return e == null? null : e.getKey(); return (e == null) ? null : e.getKey();
} }
......
...@@ -547,7 +547,7 @@ public class CopyOnWriteArrayList<E> ...@@ -547,7 +547,7 @@ public class CopyOnWriteArrayList<E>
* @param fromIndex index of first element to be removed * @param fromIndex index of first element to be removed
* @param toIndex index after last element to be removed * @param toIndex index after last element to be removed
* @throws IndexOutOfBoundsException if fromIndex or toIndex out of range * @throws IndexOutOfBoundsException if fromIndex or toIndex out of range
* (@code{fromIndex < 0 || toIndex > size() || toIndex < fromIndex}) * ({@code{fromIndex < 0 || toIndex > size() || toIndex < fromIndex})
*/ */
private void removeRange(int fromIndex, int toIndex) { private void removeRange(int fromIndex, int toIndex) {
final ReentrantLock lock = this.lock; final ReentrantLock lock = this.lock;
...@@ -989,7 +989,7 @@ public class CopyOnWriteArrayList<E> ...@@ -989,7 +989,7 @@ public class CopyOnWriteArrayList<E>
} }
private static class COWIterator<E> implements ListIterator<E> { private static class COWIterator<E> implements ListIterator<E> {
/** Snapshot of the array **/ /** Snapshot of the array */
private final Object[] snapshot; private final Object[] snapshot;
/** Index of element to be returned by subsequent call to next. */ /** Index of element to be returned by subsequent call to next. */
private int cursor; private int cursor;
......
...@@ -59,24 +59,23 @@ import java.util.*; ...@@ -59,24 +59,23 @@ import java.util.*;
* copy-on-write set to maintain a set of Handler objects that * copy-on-write set to maintain a set of Handler objects that
* perform some action upon state updates. * perform some action upon state updates.
* *
* <pre> * <pre> {@code
* class Handler { void handle(); ... } * class Handler { void handle(); ... }
* *
* class X { * class X {
* private final CopyOnWriteArraySet&lt;Handler&gt; handlers * private final CopyOnWriteArraySet<Handler> handlers
* = new CopyOnWriteArraySet&lt;Handler&gt;(); * = new CopyOnWriteArraySet<Handler>();
* public void addHandler(Handler h) { handlers.add(h); } * public void addHandler(Handler h) { handlers.add(h); }
* *
* private long internalState; * private long internalState;
* private synchronized void changeState() { internalState = ...; } * private synchronized void changeState() { internalState = ...; }
* *
* public void update() { * public void update() {
* changeState(); * changeState();
* for (Handler handler : handlers) * for (Handler handler : handlers)
* handler.handle(); * handler.handle();
* } * }
* } * }}</pre>
* </pre>
* *
* <p>This class is a member of the * <p>This class is a member of the
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> * <a href="{@docRoot}/../technotes/guides/collections/index.html">
......
...@@ -175,7 +175,7 @@ public class CountDownLatch { ...@@ -175,7 +175,7 @@ public class CountDownLatch {
} }
protected int tryAcquireShared(int acquires) { protected int tryAcquireShared(int acquires) {
return getState() == 0? 1 : -1; return (getState() == 0) ? 1 : -1;
} }
protected boolean tryReleaseShared(int releases) { protected boolean tryReleaseShared(int releases) {
......
...@@ -482,12 +482,14 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E> ...@@ -482,12 +482,14 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
/** /**
* Returns an iterator over all the elements (both expired and * Returns an iterator over all the elements (both expired and
* unexpired) in this queue. The iterator does not return the * unexpired) in this queue. The iterator does not return the
* elements in any particular order. The returned * elements in any particular order.
* <tt>Iterator</tt> is a "weakly consistent" iterator that will *
* never throw {@link ConcurrentModificationException}, and * <p>The returned iterator is a "weakly consistent" iterator that
* guarantees to traverse elements as they existed upon * will never throw {@link java.util.ConcurrentModificationException
* construction of the iterator, and may (but is not guaranteed * ConcurrentModificationException}, and guarantees to traverse
* to) reflect any modifications subsequent to construction. * elements as they existed upon construction of the iterator, and
* may (but is not guaranteed to) reflect any modifications
* subsequent to construction.
* *
* @return an iterator over the elements in this queue * @return an iterator over the elements in this queue
*/ */
......
...@@ -355,7 +355,9 @@ public class Exchanger<V> { ...@@ -355,7 +355,9 @@ public class Exchanger<V> {
else if (y == null && // Try to occupy else if (y == null && // Try to occupy
slot.compareAndSet(null, me)) { slot.compareAndSet(null, me)) {
if (index == 0) // Blocking wait for slot 0 if (index == 0) // Blocking wait for slot 0
return timed? awaitNanos(me, slot, nanos): await(me, slot); return timed ?
awaitNanos(me, slot, nanos) :
await(me, slot);
Object v = spinWait(me, slot); // Spin wait for non-0 Object v = spinWait(me, slot); // Spin wait for non-0
if (v != CANCEL) if (v != CANCEL)
return v; return v;
...@@ -597,8 +599,8 @@ public class Exchanger<V> { ...@@ -597,8 +599,8 @@ public class Exchanger<V> {
* dormant until one of two things happens: * dormant until one of two things happens:
* <ul> * <ul>
* <li>Some other thread enters the exchange; or * <li>Some other thread enters the exchange; or
* <li>Some other thread {@linkplain Thread#interrupt interrupts} the current * <li>Some other thread {@linkplain Thread#interrupt interrupts}
* thread. * the current thread.
* </ul> * </ul>
* <p>If the current thread: * <p>If the current thread:
* <ul> * <ul>
...@@ -616,7 +618,7 @@ public class Exchanger<V> { ...@@ -616,7 +618,7 @@ public class Exchanger<V> {
*/ */
public V exchange(V x) throws InterruptedException { public V exchange(V x) throws InterruptedException {
if (!Thread.interrupted()) { if (!Thread.interrupted()) {
Object v = doExchange(x == null? NULL_ITEM : x, false, 0); Object v = doExchange((x == null) ? NULL_ITEM : x, false, 0);
if (v == NULL_ITEM) if (v == NULL_ITEM)
return null; return null;
if (v != CANCEL) if (v != CANCEL)
...@@ -671,7 +673,7 @@ public class Exchanger<V> { ...@@ -671,7 +673,7 @@ public class Exchanger<V> {
public V exchange(V x, long timeout, TimeUnit unit) public V exchange(V x, long timeout, TimeUnit unit)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
if (!Thread.interrupted()) { if (!Thread.interrupted()) {
Object v = doExchange(x == null? NULL_ITEM : x, Object v = doExchange((x == null) ? NULL_ITEM : x,
true, unit.toNanos(timeout)); true, unit.toNanos(timeout));
if (v == NULL_ITEM) if (v == NULL_ITEM)
return null; return null;
......
...@@ -79,37 +79,37 @@ package java.util.concurrent; ...@@ -79,37 +79,37 @@ package java.util.concurrent;
* serializes the submission of tasks to a second executor, * serializes the submission of tasks to a second executor,
* illustrating a composite executor. * illustrating a composite executor.
* *
* <pre> * <pre> {@code
* class SerialExecutor implements Executor { * class SerialExecutor implements Executor {
* final Queue&lt;Runnable&gt; tasks = new ArrayDeque&lt;Runnable&gt;(); * final Queue<Runnable> tasks = new ArrayDeque<Runnable>();
* final Executor executor; * final Executor executor;
* Runnable active; * Runnable active;
* *
* SerialExecutor(Executor executor) { * SerialExecutor(Executor executor) {
* this.executor = executor; * this.executor = executor;
* } * }
* *
* public synchronized void execute(final Runnable r) { * public synchronized void execute(final Runnable r) {
* tasks.offer(new Runnable() { * tasks.offer(new Runnable() {
* public void run() { * public void run() {
* try { * try {
* r.run(); * r.run();
* } finally { * } finally {
* scheduleNext(); * scheduleNext();
* }
* }
* });
* if (active == null) {
* scheduleNext();
* } * }
* }
* });
* if (active == null) {
* scheduleNext();
* } * }
* }
* *
* protected synchronized void scheduleNext() { * protected synchronized void scheduleNext() {
* if ((active = tasks.poll()) != null) { * if ((active = tasks.poll()) != null) {
* executor.execute(active); * executor.execute(active);
* }
* } * }
* }</pre> * }
* }}</pre>
* *
* The <tt>Executor</tt> implementations provided in this package * The <tt>Executor</tt> implementations provided in this package
* implement {@link ExecutorService}, which is a more extensive * implement {@link ExecutorService}, which is a more extensive
......
...@@ -197,7 +197,8 @@ public class ExecutorCompletionService<V> implements CompletionService<V> { ...@@ -197,7 +197,8 @@ public class ExecutorCompletionService<V> implements CompletionService<V> {
return completionQueue.poll(); return completionQueue.poll();
} }
public Future<V> poll(long timeout, TimeUnit unit) throws InterruptedException { public Future<V> poll(long timeout, TimeUnit unit)
throws InterruptedException {
return completionQueue.poll(timeout, unit); return completionQueue.poll(timeout, unit);
} }
......
...@@ -83,7 +83,7 @@ public class Executors { ...@@ -83,7 +83,7 @@ public class Executors {
* *
* @param nThreads the number of threads in the pool * @param nThreads the number of threads in the pool
* @return the newly created thread pool * @return the newly created thread pool
* @throws IllegalArgumentException if <tt>nThreads &lt;= 0</tt> * @throws IllegalArgumentException if {@code nThreads <= 0}
*/ */
public static ExecutorService newFixedThreadPool(int nThreads) { public static ExecutorService newFixedThreadPool(int nThreads) {
return new ThreadPoolExecutor(nThreads, nThreads, return new ThreadPoolExecutor(nThreads, nThreads,
...@@ -108,7 +108,7 @@ public class Executors { ...@@ -108,7 +108,7 @@ public class Executors {
* @param threadFactory the factory to use when creating new threads * @param threadFactory the factory to use when creating new threads
* @return the newly created thread pool * @return the newly created thread pool
* @throws NullPointerException if threadFactory is null * @throws NullPointerException if threadFactory is null
* @throws IllegalArgumentException if <tt>nThreads &lt;= 0</tt> * @throws IllegalArgumentException if {@code nThreads <= 0}
*/ */
public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) { public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) {
return new ThreadPoolExecutor(nThreads, nThreads, return new ThreadPoolExecutor(nThreads, nThreads,
...@@ -242,7 +242,7 @@ public class Executors { ...@@ -242,7 +242,7 @@ public class Executors {
* @param corePoolSize the number of threads to keep in the pool, * @param corePoolSize the number of threads to keep in the pool,
* even if they are idle. * even if they are idle.
* @return a newly created scheduled thread pool * @return a newly created scheduled thread pool
* @throws IllegalArgumentException if <tt>corePoolSize &lt; 0</tt> * @throws IllegalArgumentException if {@code corePoolSize < 0}
*/ */
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) { public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) {
return new ScheduledThreadPoolExecutor(corePoolSize); return new ScheduledThreadPoolExecutor(corePoolSize);
...@@ -256,7 +256,7 @@ public class Executors { ...@@ -256,7 +256,7 @@ public class Executors {
* @param threadFactory the factory to use when the executor * @param threadFactory the factory to use when the executor
* creates a new thread. * creates a new thread.
* @return a newly created scheduled thread pool * @return a newly created scheduled thread pool
* @throws IllegalArgumentException if <tt>corePoolSize &lt; 0</tt> * @throws IllegalArgumentException if {@code corePoolSize < 0}
* @throws NullPointerException if threadFactory is null * @throws NullPointerException if threadFactory is null
*/ */
public static ScheduledExecutorService newScheduledThreadPool( public static ScheduledExecutorService newScheduledThreadPool(
...@@ -562,8 +562,8 @@ public class Executors { ...@@ -562,8 +562,8 @@ public class Executors {
DefaultThreadFactory() { DefaultThreadFactory() {
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
group = (s != null)? s.getThreadGroup() : group = (s != null) ? s.getThreadGroup() :
Thread.currentThread().getThreadGroup(); Thread.currentThread().getThreadGroup();
namePrefix = "pool-" + namePrefix = "pool-" +
poolNumber.getAndIncrement() + poolNumber.getAndIncrement() +
"-thread-"; "-thread-";
...@@ -669,7 +669,7 @@ public class Executors { ...@@ -669,7 +669,7 @@ public class Executors {
FinalizableDelegatedExecutorService(ExecutorService executor) { FinalizableDelegatedExecutorService(ExecutorService executor) {
super(executor); super(executor);
} }
protected void finalize() { protected void finalize() {
super.shutdown(); super.shutdown();
} }
} }
......
...@@ -47,21 +47,21 @@ package java.util.concurrent; ...@@ -47,21 +47,21 @@ package java.util.concurrent;
* computation has completed, the computation cannot be cancelled. * computation has completed, the computation cannot be cancelled.
* If you would like to use a <tt>Future</tt> for the sake * If you would like to use a <tt>Future</tt> for the sake
* of cancellability but not provide a usable result, you can * of cancellability but not provide a usable result, you can
* declare types of the form <tt>Future&lt;?&gt;</tt> and * declare types of the form {@code Future<?>} and
* return <tt>null</tt> as a result of the underlying task. * return <tt>null</tt> as a result of the underlying task.
* *
* <p> * <p>
* <b>Sample Usage</b> (Note that the following classes are all * <b>Sample Usage</b> (Note that the following classes are all
* made-up.) <p> * made-up.) <p>
* <pre> * <pre> {@code
* interface ArchiveSearcher { String search(String target); } * interface ArchiveSearcher { String search(String target); }
* class App { * class App {
* ExecutorService executor = ... * ExecutorService executor = ...
* ArchiveSearcher searcher = ... * ArchiveSearcher searcher = ...
* void showSearch(final String target) * void showSearch(final String target)
* throws InterruptedException { * throws InterruptedException {
* Future&lt;String&gt; future * Future<String> future
* = executor.submit(new Callable&lt;String&gt;() { * = executor.submit(new Callable<String>() {
* public String call() { * public String call() {
* return searcher.search(target); * return searcher.search(target);
* }}); * }});
...@@ -70,20 +70,18 @@ package java.util.concurrent; ...@@ -70,20 +70,18 @@ package java.util.concurrent;
* displayText(future.get()); // use future * displayText(future.get()); // use future
* } catch (ExecutionException ex) { cleanup(); return; } * } catch (ExecutionException ex) { cleanup(); return; }
* } * }
* } * }}</pre>
* </pre>
* *
* The {@link FutureTask} class is an implementation of <tt>Future</tt> that * The {@link FutureTask} class is an implementation of <tt>Future</tt> that
* implements <tt>Runnable</tt>, and so may be executed by an <tt>Executor</tt>. * implements <tt>Runnable</tt>, and so may be executed by an <tt>Executor</tt>.
* For example, the above construction with <tt>submit</tt> could be replaced by: * For example, the above construction with <tt>submit</tt> could be replaced by:
* <pre> * <pre> {@code
* FutureTask&lt;String&gt; future = * FutureTask<String> future =
* new FutureTask&lt;String&gt;(new Callable&lt;String&gt;() { * new FutureTask<String>(new Callable<String>() {
* public String call() { * public String call() {
* return searcher.search(target); * return searcher.search(target);
* }}); * }});
* executor.execute(future); * executor.execute(future);}</pre>
* </pre>
* *
* <p>Memory consistency effects: Actions taken by the asynchronous computation * <p>Memory consistency effects: Actions taken by the asynchronous computation
* <a href="package-summary.html#MemoryVisibility"> <i>happen-before</i></a> * <a href="package-summary.html#MemoryVisibility"> <i>happen-before</i></a>
......
...@@ -85,7 +85,7 @@ public class FutureTask<V> implements RunnableFuture<V> { ...@@ -85,7 +85,7 @@ public class FutureTask<V> implements RunnableFuture<V> {
* @param result the result to return on successful completion. If * @param result the result to return on successful completion. If
* you don't need a particular result, consider using * you don't need a particular result, consider using
* constructions of the form: * constructions of the form:
* <tt>Future&lt;?&gt; f = new FutureTask&lt;Object&gt;(runnable, null)</tt> * {@code Future<?> f = new FutureTask<Void>(runnable, null)}
* @throws NullPointerException if runnable is null * @throws NullPointerException if runnable is null
*/ */
public FutureTask(Runnable runnable, V result) { public FutureTask(Runnable runnable, V result) {
......
...@@ -1004,12 +1004,13 @@ public class LinkedBlockingDeque<E> ...@@ -1004,12 +1004,13 @@ public class LinkedBlockingDeque<E>
/** /**
* Returns an iterator over the elements in this deque in proper sequence. * Returns an iterator over the elements in this deque in proper sequence.
* The elements will be returned in order from first (head) to last (tail). * The elements will be returned in order from first (head) to last (tail).
* The returned {@code Iterator} is a "weakly consistent" iterator that *
* <p>The returned iterator is a "weakly consistent" iterator that
* will never throw {@link java.util.ConcurrentModificationException * will never throw {@link java.util.ConcurrentModificationException
* ConcurrentModificationException}, * ConcurrentModificationException}, and guarantees to traverse
* and guarantees to traverse elements as they existed upon * elements as they existed upon construction of the iterator, and
* construction of the iterator, and may (but is not guaranteed to) * may (but is not guaranteed to) reflect any modifications
* reflect any modifications subsequent to construction. * subsequent to construction.
* *
* @return an iterator over the elements in this deque in proper sequence * @return an iterator over the elements in this deque in proper sequence
*/ */
...@@ -1021,12 +1022,13 @@ public class LinkedBlockingDeque<E> ...@@ -1021,12 +1022,13 @@ public class LinkedBlockingDeque<E>
* Returns an iterator over the elements in this deque in reverse * Returns an iterator over the elements in this deque in reverse
* sequential order. The elements will be returned in order from * sequential order. The elements will be returned in order from
* last (tail) to first (head). * last (tail) to first (head).
* The returned {@code Iterator} is a "weakly consistent" iterator that *
* <p>The returned iterator is a "weakly consistent" iterator that
* will never throw {@link java.util.ConcurrentModificationException * will never throw {@link java.util.ConcurrentModificationException
* ConcurrentModificationException}, * ConcurrentModificationException}, and guarantees to traverse
* and guarantees to traverse elements as they existed upon * elements as they existed upon construction of the iterator, and
* construction of the iterator, and may (but is not guaranteed to) * may (but is not guaranteed to) reflect any modifications
* reflect any modifications subsequent to construction. * subsequent to construction.
*/ */
public Iterator<E> descendingIterator() { public Iterator<E> descendingIterator() {
return new DescendingItr(); return new DescendingItr();
......
...@@ -159,7 +159,9 @@ public abstract class RecursiveAction extends ForkJoinTask<Void> { ...@@ -159,7 +159,9 @@ public abstract class RecursiveAction extends ForkJoinTask<Void> {
protected abstract void compute(); protected abstract void compute();
/** /**
* Always returns null. * Always returns {@code null}.
*
* @return {@code null} always
*/ */
public final Void getRawResult() { return null; } public final Void getRawResult() { return null; }
......
...@@ -72,24 +72,23 @@ import java.util.*; ...@@ -72,24 +72,23 @@ import java.util.*;
* Here is a class with a method that sets up a ScheduledExecutorService * Here is a class with a method that sets up a ScheduledExecutorService
* to beep every ten seconds for an hour: * to beep every ten seconds for an hour:
* *
* <pre> * <pre> {@code
* import static java.util.concurrent.TimeUnit.*; * import static java.util.concurrent.TimeUnit.*;
* class BeeperControl { * class BeeperControl {
* private final ScheduledExecutorService scheduler = * private final ScheduledExecutorService scheduler =
* Executors.newScheduledThreadPool(1); * Executors.newScheduledThreadPool(1);
* *
* public void beepForAnHour() { * public void beepForAnHour() {
* final Runnable beeper = new Runnable() { * final Runnable beeper = new Runnable() {
* public void run() { System.out.println("beep"); } * public void run() { System.out.println("beep"); }
* }; * };
* final ScheduledFuture&lt;?&gt; beeperHandle = * final ScheduledFuture<?> beeperHandle =
* scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS); * scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
* scheduler.schedule(new Runnable() { * scheduler.schedule(new Runnable() {
* public void run() { beeperHandle.cancel(true); } * public void run() { beeperHandle.cancel(true); }
* }, 60 * 60, SECONDS); * }, 60 * 60, SECONDS);
* } * }
* } * }}</pre>
* </pre>
* *
* @since 1.5 * @since 1.5
* @author Doug Lea * @author Doug Lea
......
...@@ -62,8 +62,8 @@ import java.util.*; ...@@ -62,8 +62,8 @@ import java.util.*;
* time of cancellation. * time of cancellation.
* *
* <p>Successive executions of a task scheduled via * <p>Successive executions of a task scheduled via
* <code>scheduleAtFixedRate</code> or * {@code scheduleAtFixedRate} or
* <code>scheduleWithFixedDelay</code> do not overlap. While different * {@code scheduleWithFixedDelay} do not overlap. While different
* executions may be performed by different threads, the effects of * executions may be performed by different threads, the effects of
* prior executions <a * prior executions <a
* href="package-summary.html#MemoryVisibility"><i>happen-before</i></a> * href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
...@@ -436,7 +436,7 @@ public class ScheduledThreadPoolExecutor ...@@ -436,7 +436,7 @@ public class ScheduledThreadPoolExecutor
* @throws NullPointerException if {@code threadFactory} is null * @throws NullPointerException if {@code threadFactory} is null
*/ */
public ScheduledThreadPoolExecutor(int corePoolSize, public ScheduledThreadPoolExecutor(int corePoolSize,
ThreadFactory threadFactory) { ThreadFactory threadFactory) {
super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS, super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS,
new DelayedWorkQueue(), threadFactory); new DelayedWorkQueue(), threadFactory);
} }
...@@ -453,7 +453,7 @@ public class ScheduledThreadPoolExecutor ...@@ -453,7 +453,7 @@ public class ScheduledThreadPoolExecutor
* @throws NullPointerException if {@code handler} is null * @throws NullPointerException if {@code handler} is null
*/ */
public ScheduledThreadPoolExecutor(int corePoolSize, public ScheduledThreadPoolExecutor(int corePoolSize,
RejectedExecutionHandler handler) { RejectedExecutionHandler handler) {
super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS, super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS,
new DelayedWorkQueue(), handler); new DelayedWorkQueue(), handler);
} }
...@@ -473,8 +473,8 @@ public class ScheduledThreadPoolExecutor ...@@ -473,8 +473,8 @@ public class ScheduledThreadPoolExecutor
* {@code handler} is null * {@code handler} is null
*/ */
public ScheduledThreadPoolExecutor(int corePoolSize, public ScheduledThreadPoolExecutor(int corePoolSize,
ThreadFactory threadFactory, ThreadFactory threadFactory,
RejectedExecutionHandler handler) { RejectedExecutionHandler handler) {
super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS, super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS,
new DelayedWorkQueue(), threadFactory, handler); new DelayedWorkQueue(), threadFactory, handler);
} }
......
...@@ -223,7 +223,7 @@ public class Semaphore implements java.io.Serializable { ...@@ -223,7 +223,7 @@ public class Semaphore implements java.io.Serializable {
/** /**
* NonFair version * NonFair version
*/ */
final static class NonfairSync extends Sync { static final class NonfairSync extends Sync {
private static final long serialVersionUID = -2694183684443567898L; private static final long serialVersionUID = -2694183684443567898L;
NonfairSync(int permits) { NonfairSync(int permits) {
...@@ -238,7 +238,7 @@ public class Semaphore implements java.io.Serializable { ...@@ -238,7 +238,7 @@ public class Semaphore implements java.io.Serializable {
/** /**
* Fair version * Fair version
*/ */
final static class FairSync extends Sync { static final class FairSync extends Sync {
private static final long serialVersionUID = 2014338818796000944L; private static final long serialVersionUID = 2014338818796000944L;
FairSync(int permits) { FairSync(int permits) {
...@@ -282,7 +282,7 @@ public class Semaphore implements java.io.Serializable { ...@@ -282,7 +282,7 @@ public class Semaphore implements java.io.Serializable {
* else {@code false} * else {@code false}
*/ */
public Semaphore(int permits, boolean fair) { public Semaphore(int permits, boolean fair) {
sync = (fair)? new FairSync(permits) : new NonfairSync(permits); sync = fair ? new FairSync(permits) : new NonfairSync(permits);
} }
/** /**
......
...@@ -63,9 +63,9 @@ import java.util.Random; ...@@ -63,9 +63,9 @@ import java.util.Random;
*/ */
public class ThreadLocalRandom extends Random { public class ThreadLocalRandom extends Random {
// same constants as Random, but must be redeclared because private // same constants as Random, but must be redeclared because private
private final static long multiplier = 0x5DEECE66DL; private static final long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL; private static final long addend = 0xBL;
private final static long mask = (1L << 48) - 1; private static final long mask = (1L << 48) - 1;
/** /**
* The random seed. We can't use super.seed. * The random seed. We can't use super.seed.
......
...@@ -53,12 +53,12 @@ package java.util.concurrent; ...@@ -53,12 +53,12 @@ package java.util.concurrent;
* java.util.concurrent.locks.Lock lock} is not available: * java.util.concurrent.locks.Lock lock} is not available:
* *
* <pre> Lock lock = ...; * <pre> Lock lock = ...;
* if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ... * if (lock.tryLock(50L, TimeUnit.MILLISECONDS)) ...
* </pre> * </pre>
* while this code will timeout in 50 seconds: * while this code will timeout in 50 seconds:
* <pre> * <pre>
* Lock lock = ...; * Lock lock = ...;
* if ( lock.tryLock(50L, TimeUnit.SECONDS) ) ... * if (lock.tryLock(50L, TimeUnit.SECONDS)) ...
* </pre> * </pre>
* *
* Note however, that there is no guarantee that a particular timeout * Note however, that there is no guarantee that a particular timeout
...@@ -291,7 +291,8 @@ public enum TimeUnit { ...@@ -291,7 +291,8 @@ public enum TimeUnit {
abstract int excessNanos(long d, long m); abstract int excessNanos(long d, long m);
/** /**
* Performs a timed <tt>Object.wait</tt> using this time unit. * Performs a timed {@link Object#wait(long, int) Object.wait}
* using this time unit.
* This is a convenience method that converts timeout arguments * This is a convenience method that converts timeout arguments
* into the form required by the <tt>Object.wait</tt> method. * into the form required by the <tt>Object.wait</tt> method.
* *
...@@ -299,21 +300,22 @@ public enum TimeUnit { ...@@ -299,21 +300,22 @@ public enum TimeUnit {
* method (see {@link BlockingQueue#poll BlockingQueue.poll}) * method (see {@link BlockingQueue#poll BlockingQueue.poll})
* using: * using:
* *
* <pre> public synchronized Object poll(long timeout, TimeUnit unit) throws InterruptedException { * <pre> {@code
* while (empty) { * public synchronized Object poll(long timeout, TimeUnit unit)
* unit.timedWait(this, timeout); * throws InterruptedException {
* ... * while (empty) {
* } * unit.timedWait(this, timeout);
* }</pre> * ...
* }
* }}</pre>
* *
* @param obj the object to wait on * @param obj the object to wait on
* @param timeout the maximum time to wait. If less than * @param timeout the maximum time to wait. If less than
* or equal to zero, do not wait at all. * or equal to zero, do not wait at all.
* @throws InterruptedException if interrupted while waiting. * @throws InterruptedException if interrupted while waiting
* @see Object#wait(long, int)
*/ */
public void timedWait(Object obj, long timeout) public void timedWait(Object obj, long timeout)
throws InterruptedException { throws InterruptedException {
if (timeout > 0) { if (timeout > 0) {
long ms = toMillis(timeout); long ms = toMillis(timeout);
int ns = excessNanos(timeout, ms); int ns = excessNanos(timeout, ms);
...@@ -322,17 +324,18 @@ public enum TimeUnit { ...@@ -322,17 +324,18 @@ public enum TimeUnit {
} }
/** /**
* Performs a timed <tt>Thread.join</tt> using this time unit. * Performs a timed {@link Thread#join(long, int) Thread.join}
* using this time unit.
* This is a convenience method that converts time arguments into the * This is a convenience method that converts time arguments into the
* form required by the <tt>Thread.join</tt> method. * form required by the <tt>Thread.join</tt> method.
*
* @param thread the thread to wait for * @param thread the thread to wait for
* @param timeout the maximum time to wait. If less than * @param timeout the maximum time to wait. If less than
* or equal to zero, do not wait at all. * or equal to zero, do not wait at all.
* @throws InterruptedException if interrupted while waiting. * @throws InterruptedException if interrupted while waiting
* @see Thread#join(long, int)
*/ */
public void timedJoin(Thread thread, long timeout) public void timedJoin(Thread thread, long timeout)
throws InterruptedException { throws InterruptedException {
if (timeout > 0) { if (timeout > 0) {
long ms = toMillis(timeout); long ms = toMillis(timeout);
int ns = excessNanos(timeout, ms); int ns = excessNanos(timeout, ms);
...@@ -341,13 +344,14 @@ public enum TimeUnit { ...@@ -341,13 +344,14 @@ public enum TimeUnit {
} }
/** /**
* Performs a <tt>Thread.sleep</tt> using this unit. * Performs a {@link Thread#sleep(long, int) Thread.sleep} using
* this time unit.
* This is a convenience method that converts time arguments into the * This is a convenience method that converts time arguments into the
* form required by the <tt>Thread.sleep</tt> method. * form required by the <tt>Thread.sleep</tt> method.
*
* @param timeout the minimum time to sleep. If less than * @param timeout the minimum time to sleep. If less than
* or equal to zero, do not sleep at all. * or equal to zero, do not sleep at all.
* @throws InterruptedException if interrupted while sleeping. * @throws InterruptedException if interrupted while sleeping
* @see Thread#sleep
*/ */
public void sleep(long timeout) throws InterruptedException { public void sleep(long timeout) throws InterruptedException {
if (timeout > 0) { if (timeout > 0) {
......
...@@ -55,7 +55,7 @@ import java.lang.reflect.*; ...@@ -55,7 +55,7 @@ import java.lang.reflect.*;
* @author Doug Lea * @author Doug Lea
* @param <T> The type of the object holding the updatable field * @param <T> The type of the object holding the updatable field
*/ */
public abstract class AtomicIntegerFieldUpdater<T> { public abstract class AtomicIntegerFieldUpdater<T> {
/** /**
* Creates and returns an updater for objects with the given field. * Creates and returns an updater for objects with the given field.
* The Class argument is needed to check that reflective types and * The Class argument is needed to check that reflective types and
...@@ -279,7 +279,7 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -279,7 +279,7 @@ public abstract class AtomicIntegerFieldUpdater<T> {
sun.reflect.misc.ReflectUtil.ensureMemberAccess( sun.reflect.misc.ReflectUtil.ensureMemberAccess(
caller, tclass, null, modifiers); caller, tclass, null, modifiers);
sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
} catch(Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
......
...@@ -55,7 +55,7 @@ import java.lang.reflect.*; ...@@ -55,7 +55,7 @@ import java.lang.reflect.*;
* @author Doug Lea * @author Doug Lea
* @param <T> The type of the object holding the updatable field * @param <T> The type of the object holding the updatable field
*/ */
public abstract class AtomicLongFieldUpdater<T> { public abstract class AtomicLongFieldUpdater<T> {
/** /**
* Creates and returns an updater for objects with the given field. * Creates and returns an updater for objects with the given field.
* The Class argument is needed to check that reflective types and * The Class argument is needed to check that reflective types and
...@@ -278,7 +278,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -278,7 +278,7 @@ public abstract class AtomicLongFieldUpdater<T> {
sun.reflect.misc.ReflectUtil.ensureMemberAccess( sun.reflect.misc.ReflectUtil.ensureMemberAccess(
caller, tclass, null, modifiers); caller, tclass, null, modifiers);
sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
} catch(Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
...@@ -331,7 +331,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -331,7 +331,7 @@ public abstract class AtomicLongFieldUpdater<T> {
if (cclass.isInstance(obj)) { if (cclass.isInstance(obj)) {
return; return;
} }
throw new RuntimeException ( throw new RuntimeException(
new IllegalAccessException("Class " + new IllegalAccessException("Class " +
cclass.getName() + cclass.getName() +
" can not access a protected member of class " + " can not access a protected member of class " +
...@@ -361,7 +361,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -361,7 +361,7 @@ public abstract class AtomicLongFieldUpdater<T> {
sun.reflect.misc.ReflectUtil.ensureMemberAccess( sun.reflect.misc.ReflectUtil.ensureMemberAccess(
caller, tclass, null, modifiers); caller, tclass, null, modifiers);
sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass);
} catch(Exception ex) { } catch (Exception ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
...@@ -387,7 +387,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -387,7 +387,7 @@ public abstract class AtomicLongFieldUpdater<T> {
public boolean compareAndSet(T obj, long expect, long update) { public boolean compareAndSet(T obj, long expect, long update) {
if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj); if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
synchronized(this) { synchronized (this) {
long v = unsafe.getLong(obj, offset); long v = unsafe.getLong(obj, offset);
if (v != expect) if (v != expect)
return false; return false;
...@@ -402,7 +402,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -402,7 +402,7 @@ public abstract class AtomicLongFieldUpdater<T> {
public void set(T obj, long newValue) { public void set(T obj, long newValue) {
if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj); if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
synchronized(this) { synchronized (this) {
unsafe.putLong(obj, offset, newValue); unsafe.putLong(obj, offset, newValue);
} }
} }
...@@ -413,7 +413,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -413,7 +413,7 @@ public abstract class AtomicLongFieldUpdater<T> {
public long get(T obj) { public long get(T obj) {
if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj); if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
synchronized(this) { synchronized (this) {
return unsafe.getLong(obj, offset); return unsafe.getLong(obj, offset);
} }
} }
...@@ -422,7 +422,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -422,7 +422,7 @@ public abstract class AtomicLongFieldUpdater<T> {
if (cclass.isInstance(obj)) { if (cclass.isInstance(obj)) {
return; return;
} }
throw new RuntimeException ( throw new RuntimeException(
new IllegalAccessException("Class " + new IllegalAccessException("Class " +
cclass.getName() + cclass.getName() +
" can not access a protected member of class " + " can not access a protected member of class " +
......
...@@ -45,13 +45,13 @@ import java.lang.reflect.*; ...@@ -45,13 +45,13 @@ import java.lang.reflect.*;
* independently subject to atomic updates. For example, a tree node * independently subject to atomic updates. For example, a tree node
* might be declared as * might be declared as
* *
* <pre> * <pre> {@code
* class Node { * class Node {
* private volatile Node left, right; * private volatile Node left, right;
* *
* private static final AtomicReferenceFieldUpdater&lt;Node, Node&gt; leftUpdater = * private static final AtomicReferenceFieldUpdater<Node, Node> leftUpdater =
* AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "left"); * AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "left");
* private static AtomicReferenceFieldUpdater&lt;Node, Node&gt; rightUpdater = * private static AtomicReferenceFieldUpdater<Node, Node> rightUpdater =
* AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "right"); * AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "right");
* *
* Node getLeft() { return left; } * Node getLeft() { return left; }
...@@ -59,8 +59,7 @@ import java.lang.reflect.*; ...@@ -59,8 +59,7 @@ import java.lang.reflect.*;
* return leftUpdater.compareAndSet(this, expect, update); * return leftUpdater.compareAndSet(this, expect, update);
* } * }
* // ... and so on * // ... and so on
* } * }}</pre>
* </pre>
* *
* <p>Note that the guarantees of the {@code compareAndSet} * <p>Note that the guarantees of the {@code compareAndSet}
* method in this class are weaker than in other atomic classes. * method in this class are weaker than in other atomic classes.
...@@ -74,7 +73,7 @@ import java.lang.reflect.*; ...@@ -74,7 +73,7 @@ import java.lang.reflect.*;
* @param <T> The type of the object holding the updatable field * @param <T> The type of the object holding the updatable field
* @param <V> The type of the field * @param <V> The type of the field
*/ */
public abstract class AtomicReferenceFieldUpdater<T, V> { public abstract class AtomicReferenceFieldUpdater<T, V> {
/** /**
* Creates and returns an updater for objects with the given field. * Creates and returns an updater for objects with the given field.
...@@ -291,7 +290,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> { ...@@ -291,7 +290,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
if (cclass.isInstance(obj)) { if (cclass.isInstance(obj)) {
return; return;
} }
throw new RuntimeException ( throw new RuntimeException(
new IllegalAccessException("Class " + new IllegalAccessException("Class " +
cclass.getName() + cclass.getName() +
" can not access a protected member of class " + " can not access a protected member of class " +
......
...@@ -990,7 +990,8 @@ public abstract class AbstractQueuedLongSynchronizer ...@@ -990,7 +990,8 @@ public abstract class AbstractQueuedLongSynchronizer
* can represent anything you like. * can represent anything you like.
* @throws InterruptedException if the current thread is interrupted * @throws InterruptedException if the current thread is interrupted
*/ */
public final void acquireInterruptibly(long arg) throws InterruptedException { public final void acquireInterruptibly(long arg)
throws InterruptedException {
if (Thread.interrupted()) if (Thread.interrupted())
throw new InterruptedException(); throw new InterruptedException();
if (!tryAcquire(arg)) if (!tryAcquire(arg))
...@@ -1014,7 +1015,8 @@ public abstract class AbstractQueuedLongSynchronizer ...@@ -1014,7 +1015,8 @@ public abstract class AbstractQueuedLongSynchronizer
* @return {@code true} if acquired; {@code false} if timed out * @return {@code true} if acquired; {@code false} if timed out
* @throws InterruptedException if the current thread is interrupted * @throws InterruptedException if the current thread is interrupted
*/ */
public final boolean tryAcquireNanos(long arg, long nanosTimeout) throws InterruptedException { public final boolean tryAcquireNanos(long arg, long nanosTimeout)
throws InterruptedException {
if (Thread.interrupted()) if (Thread.interrupted())
throw new InterruptedException(); throw new InterruptedException();
return tryAcquire(arg) || return tryAcquire(arg) ||
...@@ -1070,7 +1072,8 @@ public abstract class AbstractQueuedLongSynchronizer ...@@ -1070,7 +1072,8 @@ public abstract class AbstractQueuedLongSynchronizer
* you like. * you like.
* @throws InterruptedException if the current thread is interrupted * @throws InterruptedException if the current thread is interrupted
*/ */
public final void acquireSharedInterruptibly(long arg) throws InterruptedException { public final void acquireSharedInterruptibly(long arg)
throws InterruptedException {
if (Thread.interrupted()) if (Thread.interrupted())
throw new InterruptedException(); throw new InterruptedException();
if (tryAcquireShared(arg) < 0) if (tryAcquireShared(arg) < 0)
...@@ -1093,7 +1096,8 @@ public abstract class AbstractQueuedLongSynchronizer ...@@ -1093,7 +1096,8 @@ public abstract class AbstractQueuedLongSynchronizer
* @return {@code true} if acquired; {@code false} if timed out * @return {@code true} if acquired; {@code false} if timed out
* @throws InterruptedException if the current thread is interrupted * @throws InterruptedException if the current thread is interrupted
*/ */
public final boolean tryAcquireSharedNanos(long arg, long nanosTimeout) throws InterruptedException { public final boolean tryAcquireSharedNanos(long arg, long nanosTimeout)
throws InterruptedException {
if (Thread.interrupted()) if (Thread.interrupted())
throw new InterruptedException(); throw new InterruptedException();
return tryAcquireShared(arg) >= 0 || return tryAcquireShared(arg) >= 0 ||
...@@ -1841,7 +1845,8 @@ public abstract class AbstractQueuedLongSynchronizer ...@@ -1841,7 +1845,8 @@ public abstract class AbstractQueuedLongSynchronizer
* <li> If interrupted while blocked in step 4, throw InterruptedException. * <li> If interrupted while blocked in step 4, throw InterruptedException.
* </ol> * </ol>
*/ */
public final long awaitNanos(long nanosTimeout) throws InterruptedException { public final long awaitNanos(long nanosTimeout)
throws InterruptedException {
if (Thread.interrupted()) if (Thread.interrupted())
throw new InterruptedException(); throw new InterruptedException();
Node node = addConditionWaiter(); Node node = addConditionWaiter();
...@@ -1885,7 +1890,8 @@ public abstract class AbstractQueuedLongSynchronizer ...@@ -1885,7 +1890,8 @@ public abstract class AbstractQueuedLongSynchronizer
* <li> If timed out while blocked in step 4, return false, else true. * <li> If timed out while blocked in step 4, return false, else true.
* </ol> * </ol>
*/ */
public final boolean awaitUntil(Date deadline) throws InterruptedException { public final boolean awaitUntil(Date deadline)
throws InterruptedException {
if (deadline == null) if (deadline == null)
throw new NullPointerException(); throw new NullPointerException();
long abstime = deadline.getTime(); long abstime = deadline.getTime();
...@@ -1928,7 +1934,8 @@ public abstract class AbstractQueuedLongSynchronizer ...@@ -1928,7 +1934,8 @@ public abstract class AbstractQueuedLongSynchronizer
* <li> If timed out while blocked in step 4, return false, else true. * <li> If timed out while blocked in step 4, return false, else true.
* </ol> * </ol>
*/ */
public final boolean await(long time, TimeUnit unit) throws InterruptedException { public final boolean await(long time, TimeUnit unit)
throws InterruptedException {
if (unit == null) if (unit == null)
throw new NullPointerException(); throw new NullPointerException();
long nanosTimeout = unit.toNanos(time); long nanosTimeout = unit.toNanos(time);
...@@ -2084,7 +2091,7 @@ public abstract class AbstractQueuedLongSynchronizer ...@@ -2084,7 +2091,7 @@ public abstract class AbstractQueuedLongSynchronizer
/** /**
* CAS waitStatus field of a node. * CAS waitStatus field of a node.
*/ */
private final static boolean compareAndSetWaitStatus(Node node, private static final boolean compareAndSetWaitStatus(Node node,
int expect, int expect,
int update) { int update) {
return unsafe.compareAndSwapInt(node, waitStatusOffset, return unsafe.compareAndSwapInt(node, waitStatusOffset,
...@@ -2094,7 +2101,7 @@ public abstract class AbstractQueuedLongSynchronizer ...@@ -2094,7 +2101,7 @@ public abstract class AbstractQueuedLongSynchronizer
/** /**
* CAS next field of a node. * CAS next field of a node.
*/ */
private final static boolean compareAndSetNext(Node node, private static final boolean compareAndSetNext(Node node,
Node expect, Node expect,
Node update) { Node update) {
return unsafe.compareAndSwapObject(node, nextOffset, expect, update); return unsafe.compareAndSwapObject(node, nextOffset, expect, update);
......
...@@ -265,7 +265,7 @@ import sun.misc.Unsafe; ...@@ -265,7 +265,7 @@ import sun.misc.Unsafe;
* boolean isSignalled() { return getState() != 0; } * boolean isSignalled() { return getState() != 0; }
* *
* protected int tryAcquireShared(int ignore) { * protected int tryAcquireShared(int ignore) {
* return isSignalled()? 1 : -1; * return isSignalled() ? 1 : -1;
* } * }
* *
* protected boolean tryReleaseShared(int ignore) { * protected boolean tryReleaseShared(int ignore) {
...@@ -1213,7 +1213,8 @@ public abstract class AbstractQueuedSynchronizer ...@@ -1213,7 +1213,8 @@ public abstract class AbstractQueuedSynchronizer
* can represent anything you like. * can represent anything you like.
* @throws InterruptedException if the current thread is interrupted * @throws InterruptedException if the current thread is interrupted
*/ */
public final void acquireInterruptibly(int arg) throws InterruptedException { public final void acquireInterruptibly(int arg)
throws InterruptedException {
if (Thread.interrupted()) if (Thread.interrupted())
throw new InterruptedException(); throw new InterruptedException();
if (!tryAcquire(arg)) if (!tryAcquire(arg))
...@@ -1237,7 +1238,8 @@ public abstract class AbstractQueuedSynchronizer ...@@ -1237,7 +1238,8 @@ public abstract class AbstractQueuedSynchronizer
* @return {@code true} if acquired; {@code false} if timed out * @return {@code true} if acquired; {@code false} if timed out
* @throws InterruptedException if the current thread is interrupted * @throws InterruptedException if the current thread is interrupted
*/ */
public final boolean tryAcquireNanos(int arg, long nanosTimeout) throws InterruptedException { public final boolean tryAcquireNanos(int arg, long nanosTimeout)
throws InterruptedException {
if (Thread.interrupted()) if (Thread.interrupted())
throw new InterruptedException(); throw new InterruptedException();
return tryAcquire(arg) || return tryAcquire(arg) ||
...@@ -1293,7 +1295,8 @@ public abstract class AbstractQueuedSynchronizer ...@@ -1293,7 +1295,8 @@ public abstract class AbstractQueuedSynchronizer
* you like. * you like.
* @throws InterruptedException if the current thread is interrupted * @throws InterruptedException if the current thread is interrupted
*/ */
public final void acquireSharedInterruptibly(int arg) throws InterruptedException { public final void acquireSharedInterruptibly(int arg)
throws InterruptedException {
if (Thread.interrupted()) if (Thread.interrupted())
throw new InterruptedException(); throw new InterruptedException();
if (tryAcquireShared(arg) < 0) if (tryAcquireShared(arg) < 0)
...@@ -1316,7 +1319,8 @@ public abstract class AbstractQueuedSynchronizer ...@@ -1316,7 +1319,8 @@ public abstract class AbstractQueuedSynchronizer
* @return {@code true} if acquired; {@code false} if timed out * @return {@code true} if acquired; {@code false} if timed out
* @throws InterruptedException if the current thread is interrupted * @throws InterruptedException if the current thread is interrupted
*/ */
public final boolean tryAcquireSharedNanos(int arg, long nanosTimeout) throws InterruptedException { public final boolean tryAcquireSharedNanos(int arg, long nanosTimeout)
throws InterruptedException {
if (Thread.interrupted()) if (Thread.interrupted())
throw new InterruptedException(); throw new InterruptedException();
return tryAcquireShared(arg) >= 0 || return tryAcquireShared(arg) >= 0 ||
...@@ -2062,7 +2066,8 @@ public abstract class AbstractQueuedSynchronizer ...@@ -2062,7 +2066,8 @@ public abstract class AbstractQueuedSynchronizer
* <li> If interrupted while blocked in step 4, throw InterruptedException. * <li> If interrupted while blocked in step 4, throw InterruptedException.
* </ol> * </ol>
*/ */
public final long awaitNanos(long nanosTimeout) throws InterruptedException { public final long awaitNanos(long nanosTimeout)
throws InterruptedException {
if (Thread.interrupted()) if (Thread.interrupted())
throw new InterruptedException(); throw new InterruptedException();
Node node = addConditionWaiter(); Node node = addConditionWaiter();
...@@ -2106,7 +2111,8 @@ public abstract class AbstractQueuedSynchronizer ...@@ -2106,7 +2111,8 @@ public abstract class AbstractQueuedSynchronizer
* <li> If timed out while blocked in step 4, return false, else true. * <li> If timed out while blocked in step 4, return false, else true.
* </ol> * </ol>
*/ */
public final boolean awaitUntil(Date deadline) throws InterruptedException { public final boolean awaitUntil(Date deadline)
throws InterruptedException {
if (deadline == null) if (deadline == null)
throw new NullPointerException(); throw new NullPointerException();
long abstime = deadline.getTime(); long abstime = deadline.getTime();
...@@ -2149,7 +2155,8 @@ public abstract class AbstractQueuedSynchronizer ...@@ -2149,7 +2155,8 @@ public abstract class AbstractQueuedSynchronizer
* <li> If timed out while blocked in step 4, return false, else true. * <li> If timed out while blocked in step 4, return false, else true.
* </ol> * </ol>
*/ */
public final boolean await(long time, TimeUnit unit) throws InterruptedException { public final boolean await(long time, TimeUnit unit)
throws InterruptedException {
if (unit == null) if (unit == null)
throw new NullPointerException(); throw new NullPointerException();
long nanosTimeout = unit.toNanos(time); long nanosTimeout = unit.toNanos(time);
...@@ -2305,7 +2312,7 @@ public abstract class AbstractQueuedSynchronizer ...@@ -2305,7 +2312,7 @@ public abstract class AbstractQueuedSynchronizer
/** /**
* CAS waitStatus field of a node. * CAS waitStatus field of a node.
*/ */
private final static boolean compareAndSetWaitStatus(Node node, private static final boolean compareAndSetWaitStatus(Node node,
int expect, int expect,
int update) { int update) {
return unsafe.compareAndSwapInt(node, waitStatusOffset, return unsafe.compareAndSwapInt(node, waitStatusOffset,
...@@ -2315,7 +2322,7 @@ public abstract class AbstractQueuedSynchronizer ...@@ -2315,7 +2322,7 @@ public abstract class AbstractQueuedSynchronizer
/** /**
* CAS next field of a node. * CAS next field of a node.
*/ */
private final static boolean compareAndSetNext(Node node, private static final boolean compareAndSetNext(Node node,
Node expect, Node expect,
Node update) { Node update) {
return unsafe.compareAndSwapObject(node, nextOffset, expect, update); return unsafe.compareAndSwapObject(node, nextOffset, expect, update);
......
...@@ -200,8 +200,8 @@ public class LockSupport { ...@@ -200,8 +200,8 @@ public class LockSupport {
* <li>Some other thread invokes {@link #unpark unpark} with the * <li>Some other thread invokes {@link #unpark unpark} with the
* current thread as the target; or * current thread as the target; or
* *
* <li>Some other thread {@linkplain Thread#interrupt interrupts} the current * <li>Some other thread {@linkplain Thread#interrupt interrupts}
* thread; or * the current thread; or
* *
* <li>The specified waiting time elapses; or * <li>The specified waiting time elapses; or
* *
......
...@@ -116,7 +116,7 @@ public class ReentrantLock implements Lock, java.io.Serializable { ...@@ -116,7 +116,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
* into fair and nonfair versions below. Uses AQS state to * into fair and nonfair versions below. Uses AQS state to
* represent the number of holds on the lock. * represent the number of holds on the lock.
*/ */
static abstract class Sync extends AbstractQueuedSynchronizer { abstract static class Sync extends AbstractQueuedSynchronizer {
private static final long serialVersionUID = -5179523762034025860L; private static final long serialVersionUID = -5179523762034025860L;
/** /**
...@@ -200,7 +200,7 @@ public class ReentrantLock implements Lock, java.io.Serializable { ...@@ -200,7 +200,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
/** /**
* Sync object for non-fair locks * Sync object for non-fair locks
*/ */
final static class NonfairSync extends Sync { static final class NonfairSync extends Sync {
private static final long serialVersionUID = 7316153563782823691L; private static final long serialVersionUID = 7316153563782823691L;
/** /**
...@@ -222,7 +222,7 @@ public class ReentrantLock implements Lock, java.io.Serializable { ...@@ -222,7 +222,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
/** /**
* Sync object for fair locks * Sync object for fair locks
*/ */
final static class FairSync extends Sync { static final class FairSync extends Sync {
private static final long serialVersionUID = -3000897897090466540L; private static final long serialVersionUID = -3000897897090466540L;
final void lock() { final void lock() {
...@@ -269,7 +269,7 @@ public class ReentrantLock implements Lock, java.io.Serializable { ...@@ -269,7 +269,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
* @param fair {@code true} if this lock should use a fair ordering policy * @param fair {@code true} if this lock should use a fair ordering policy
*/ */
public ReentrantLock(boolean fair) { public ReentrantLock(boolean fair) {
sync = (fair)? new FairSync() : new NonfairSync(); sync = fair ? new FairSync() : new NonfairSync();
} }
/** /**
...@@ -440,7 +440,8 @@ public class ReentrantLock implements Lock, java.io.Serializable { ...@@ -440,7 +440,8 @@ public class ReentrantLock implements Lock, java.io.Serializable {
* @throws NullPointerException if the time unit is null * @throws NullPointerException if the time unit is null
* *
*/ */
public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException { public boolean tryLock(long timeout, TimeUnit unit)
throws InterruptedException {
return sync.tryAcquireNanos(1, unit.toNanos(timeout)); return sync.tryAcquireNanos(1, unit.toNanos(timeout));
} }
......
...@@ -155,7 +155,7 @@ import java.util.*; ...@@ -155,7 +155,7 @@ import java.util.*;
* } * }
* // Downgrade by acquiring read lock before releasing write lock * // Downgrade by acquiring read lock before releasing write lock
* rwl.readLock().lock(); * rwl.readLock().lock();
* } finally { * } finally {
* rwl.writeLock().unlock(); // Unlock write, still hold read * rwl.writeLock().unlock(); // Unlock write, still hold read
* } * }
* } * }
...@@ -215,7 +215,8 @@ import java.util.*; ...@@ -215,7 +215,8 @@ import java.util.*;
* @author Doug Lea * @author Doug Lea
* *
*/ */
public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializable { public class ReentrantReadWriteLock
implements ReadWriteLock, java.io.Serializable {
private static final long serialVersionUID = -6992448646407690164L; private static final long serialVersionUID = -6992448646407690164L;
/** Inner class providing readlock */ /** Inner class providing readlock */
private final ReentrantReadWriteLock.ReadLock readerLock; private final ReentrantReadWriteLock.ReadLock readerLock;
...@@ -251,7 +252,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab ...@@ -251,7 +252,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
* Synchronization implementation for ReentrantReadWriteLock. * Synchronization implementation for ReentrantReadWriteLock.
* Subclassed into fair and nonfair versions. * Subclassed into fair and nonfair versions.
*/ */
static abstract class Sync extends AbstractQueuedSynchronizer { abstract static class Sync extends AbstractQueuedSynchronizer {
private static final long serialVersionUID = 6317671515068378041L; private static final long serialVersionUID = 6317671515068378041L;
/* /*
...@@ -618,7 +619,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab ...@@ -618,7 +619,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
final Thread getOwner() { final Thread getOwner() {
// Must read state before owner to ensure memory consistency // Must read state before owner to ensure memory consistency
return ((exclusiveCount(getState()) == 0)? return ((exclusiveCount(getState()) == 0) ?
null : null :
getExclusiveOwnerThread()); getExclusiveOwnerThread());
} }
...@@ -669,7 +670,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab ...@@ -669,7 +670,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
/** /**
* Nonfair version of Sync * Nonfair version of Sync
*/ */
final static class NonfairSync extends Sync { static final class NonfairSync extends Sync {
private static final long serialVersionUID = -8159625535654395037L; private static final long serialVersionUID = -8159625535654395037L;
final boolean writerShouldBlock() { final boolean writerShouldBlock() {
return false; // writers can always barge return false; // writers can always barge
...@@ -689,7 +690,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab ...@@ -689,7 +690,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
/** /**
* Fair version of Sync * Fair version of Sync
*/ */
final static class FairSync extends Sync { static final class FairSync extends Sync {
private static final long serialVersionUID = -2274990926593161451L; private static final long serialVersionUID = -2274990926593161451L;
final boolean writerShouldBlock() { final boolean writerShouldBlock() {
return hasQueuedPredecessors(); return hasQueuedPredecessors();
...@@ -702,7 +703,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab ...@@ -702,7 +703,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
/** /**
* The lock returned by method {@link ReentrantReadWriteLock#readLock}. * The lock returned by method {@link ReentrantReadWriteLock#readLock}.
*/ */
public static class ReadLock implements Lock, java.io.Serializable { public static class ReadLock implements Lock, java.io.Serializable {
private static final long serialVersionUID = -5992448646407690164L; private static final long serialVersionUID = -5992448646407690164L;
private final Sync sync; private final Sync sync;
...@@ -867,7 +868,8 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab ...@@ -867,7 +868,8 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
* @throws NullPointerException if the time unit is null * @throws NullPointerException if the time unit is null
* *
*/ */
public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException { public boolean tryLock(long timeout, TimeUnit unit)
throws InterruptedException {
return sync.tryAcquireSharedNanos(1, unit.toNanos(timeout)); return sync.tryAcquireSharedNanos(1, unit.toNanos(timeout));
} }
...@@ -908,7 +910,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab ...@@ -908,7 +910,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
/** /**
* The lock returned by method {@link ReentrantReadWriteLock#writeLock}. * The lock returned by method {@link ReentrantReadWriteLock#writeLock}.
*/ */
public static class WriteLock implements Lock, java.io.Serializable { public static class WriteLock implements Lock, java.io.Serializable {
private static final long serialVersionUID = -4992448646407690164L; private static final long serialVersionUID = -4992448646407690164L;
private final Sync sync; private final Sync sync;
...@@ -1108,7 +1110,8 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab ...@@ -1108,7 +1110,8 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
* @throws NullPointerException if the time unit is null * @throws NullPointerException if the time unit is null
* *
*/ */
public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException { public boolean tryLock(long timeout, TimeUnit unit)
throws InterruptedException {
return sync.tryAcquireNanos(1, unit.toNanos(timeout)); return sync.tryAcquireNanos(1, unit.toNanos(timeout));
} }
......
...@@ -136,5 +136,5 @@ public class Interrupt { ...@@ -136,5 +136,5 @@ public class Interrupt {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class Fun {abstract void f() throws Throwable;} private abstract static class Fun {abstract void f() throws Throwable;}
} }
...@@ -79,9 +79,9 @@ class LoopHelpers { ...@@ -79,9 +79,9 @@ class LoopHelpers {
* Basically same as java.util.Random. * Basically same as java.util.Random.
*/ */
public static class SimpleRandom { public static class SimpleRandom {
private final static long multiplier = 0x5DEECE66DL; private static final long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL; private static final long addend = 0xBL;
private final static long mask = (1L << 48) - 1; private static final long mask = (1L << 48) - 1;
static final AtomicLong seq = new AtomicLong(1); static final AtomicLong seq = new AtomicLong(1);
private long seed = System.nanoTime() + seq.getAndIncrement(); private long seed = System.nanoTime() + seq.getAndIncrement();
......
...@@ -79,9 +79,9 @@ class LoopHelpers { ...@@ -79,9 +79,9 @@ class LoopHelpers {
* Basically same as java.util.Random. * Basically same as java.util.Random.
*/ */
public static class SimpleRandom { public static class SimpleRandom {
private final static long multiplier = 0x5DEECE66DL; private static final long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL; private static final long addend = 0xBL;
private final static long mask = (1L << 48) - 1; private static final long mask = (1L << 48) - 1;
static final AtomicLong seq = new AtomicLong(1); static final AtomicLong seq = new AtomicLong(1);
private long seed = System.nanoTime() + seq.getAndIncrement(); private long seed = System.nanoTime() + seq.getAndIncrement();
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
/* /*
* @test * @test
* @bug 4486658 * @bug 4486658
* @compile MapCheck.java * @compile -source 1.5 MapCheck.java
* @run main/timeout=240 MapCheck * @run main/timeout=240 MapCheck
* @summary Times and checks basic map operations * @summary Times and checks basic map operations
*/ */
...@@ -64,7 +64,7 @@ public class MapCheck { ...@@ -64,7 +64,7 @@ public class MapCheck {
if (args.length > 0) { if (args.length > 0) {
try { try {
mapClass = Class.forName(args[0]); mapClass = Class.forName(args[0]);
} catch(ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new RuntimeException("Class " + args[0] + " not found."); throw new RuntimeException("Class " + args[0] + " not found.");
} }
} }
...@@ -102,7 +102,7 @@ public class MapCheck { ...@@ -102,7 +102,7 @@ public class MapCheck {
try { try {
Map m = (Map)cl.newInstance(); Map m = (Map)cl.newInstance();
return m; return m;
} catch(Exception e) { } catch (Exception e) {
throw new RuntimeException("Can't instantiate " + cl + ": " + e); throw new RuntimeException("Can't instantiate " + cl + ": " + e);
} }
} }
...@@ -139,7 +139,7 @@ public class MapCheck { ...@@ -139,7 +139,7 @@ public class MapCheck {
} }
} }
timer.finish(); timer.finish();
reallyAssert (sum == expect * iters); reallyAssert(sum == expect * iters);
} }
static void t2(String nm, int n, Map s, Object[] key, int expect) { static void t2(String nm, int n, Map s, Object[] key, int expect) {
...@@ -149,7 +149,7 @@ public class MapCheck { ...@@ -149,7 +149,7 @@ public class MapCheck {
if (s.remove(key[i]) != null) ++sum; if (s.remove(key[i]) != null) ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == expect); reallyAssert(sum == expect);
} }
static void t3(String nm, int n, Map s, Object[] key, int expect) { static void t3(String nm, int n, Map s, Object[] key, int expect) {
...@@ -159,7 +159,7 @@ public class MapCheck { ...@@ -159,7 +159,7 @@ public class MapCheck {
if (s.put(key[i], absent[i & absentMask]) == null) ++sum; if (s.put(key[i], absent[i & absentMask]) == null) ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == expect); reallyAssert(sum == expect);
} }
static void t4(String nm, int n, Map s, Object[] key, int expect) { static void t4(String nm, int n, Map s, Object[] key, int expect) {
...@@ -169,7 +169,7 @@ public class MapCheck { ...@@ -169,7 +169,7 @@ public class MapCheck {
if (s.containsKey(key[i])) ++sum; if (s.containsKey(key[i])) ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == expect); reallyAssert(sum == expect);
} }
static void t5(String nm, int n, Map s, Object[] key, int expect) { static void t5(String nm, int n, Map s, Object[] key, int expect) {
...@@ -179,7 +179,7 @@ public class MapCheck { ...@@ -179,7 +179,7 @@ public class MapCheck {
if (s.remove(key[i]) != null) ++sum; if (s.remove(key[i]) != null) ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == expect); reallyAssert(sum == expect);
} }
static void t6(String nm, int n, Map s, Object[] k1, Object[] k2) { static void t6(String nm, int n, Map s, Object[] k1, Object[] k2) {
...@@ -190,7 +190,7 @@ public class MapCheck { ...@@ -190,7 +190,7 @@ public class MapCheck {
if (s.get(k2[i & absentMask]) != null) ++sum; if (s.get(k2[i & absentMask]) != null) ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == n); reallyAssert(sum == n);
} }
static void t7(String nm, int n, Map s, Object[] k1, Object[] k2) { static void t7(String nm, int n, Map s, Object[] k1, Object[] k2) {
...@@ -201,7 +201,7 @@ public class MapCheck { ...@@ -201,7 +201,7 @@ public class MapCheck {
if (s.containsKey(k2[i & absentMask])) ++sum; if (s.containsKey(k2[i & absentMask])) ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == n); reallyAssert(sum == n);
} }
static void t8(String nm, int n, Map s, Object[] key, int expect) { static void t8(String nm, int n, Map s, Object[] key, int expect) {
...@@ -211,7 +211,7 @@ public class MapCheck { ...@@ -211,7 +211,7 @@ public class MapCheck {
if (s.get(key[i]) != null) ++sum; if (s.get(key[i]) != null) ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == expect); reallyAssert(sum == expect);
} }
...@@ -223,7 +223,7 @@ public class MapCheck { ...@@ -223,7 +223,7 @@ public class MapCheck {
for (int i = 0; i < absentSize; i += step) for (int i = 0; i < absentSize; i += step)
if (s.containsValue(absent[i])) ++sum; if (s.containsValue(absent[i])) ++sum;
timer.finish(); timer.finish();
reallyAssert (sum != 0); reallyAssert(sum != 0);
} }
...@@ -235,7 +235,7 @@ public class MapCheck { ...@@ -235,7 +235,7 @@ public class MapCheck {
if (ks.contains(key[i])) ++sum; if (ks.contains(key[i])) ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == size); reallyAssert(sum == size);
} }
...@@ -243,37 +243,37 @@ public class MapCheck { ...@@ -243,37 +243,37 @@ public class MapCheck {
int sum = 0; int sum = 0;
timer.start("Iter Key ", size); timer.start("Iter Key ", size);
for (Iterator it = s.keySet().iterator(); it.hasNext(); ) { for (Iterator it = s.keySet().iterator(); it.hasNext(); ) {
if(it.next() != MISSING) if (it.next() != MISSING)
++sum; ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == size); reallyAssert(sum == size);
} }
static void ittest2(Map s, int size) { static void ittest2(Map s, int size) {
int sum = 0; int sum = 0;
timer.start("Iter Value ", size); timer.start("Iter Value ", size);
for (Iterator it = s.values().iterator(); it.hasNext(); ) { for (Iterator it = s.values().iterator(); it.hasNext(); ) {
if(it.next() != MISSING) if (it.next() != MISSING)
++sum; ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == size); reallyAssert(sum == size);
} }
static void ittest3(Map s, int size) { static void ittest3(Map s, int size) {
int sum = 0; int sum = 0;
timer.start("Iter Entry ", size); timer.start("Iter Entry ", size);
for (Iterator it = s.entrySet().iterator(); it.hasNext(); ) { for (Iterator it = s.entrySet().iterator(); it.hasNext(); ) {
if(it.next() != MISSING) if (it.next() != MISSING)
++sum; ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == size); reallyAssert(sum == size);
} }
static void ittest4(Map s, int size, int pos) { static void ittest4(Map s, int size, int pos) {
IdentityHashMap seen = new IdentityHashMap(size); IdentityHashMap seen = new IdentityHashMap(size);
reallyAssert (s.size() == size); reallyAssert(s.size() == size);
int sum = 0; int sum = 0;
timer.start("Iter XEntry ", size); timer.start("Iter XEntry ", size);
Iterator it = s.entrySet().iterator(); Iterator it = s.entrySet().iterator();
...@@ -287,9 +287,9 @@ public class MapCheck { ...@@ -287,9 +287,9 @@ public class MapCheck {
if (x != MISSING) if (x != MISSING)
++sum; ++sum;
} }
reallyAssert (s.containsKey(k)); reallyAssert(s.containsKey(k));
it.remove(); it.remove();
reallyAssert (!s.containsKey(k)); reallyAssert(!s.containsKey(k));
while (it.hasNext()) { while (it.hasNext()) {
Map.Entry x = (Map.Entry)(it.next()); Map.Entry x = (Map.Entry)(it.next());
Object k2 = x.getKey(); Object k2 = x.getKey();
...@@ -298,12 +298,12 @@ public class MapCheck { ...@@ -298,12 +298,12 @@ public class MapCheck {
++sum; ++sum;
} }
reallyAssert (s.size() == size-1); reallyAssert(s.size() == size-1);
s.put(k, v); s.put(k, v);
reallyAssert (seen.size() == size); reallyAssert(seen.size() == size);
timer.finish(); timer.finish();
reallyAssert (sum == size); reallyAssert(sum == size);
reallyAssert (s.size() == size); reallyAssert(s.size() == size);
} }
...@@ -324,7 +324,7 @@ public class MapCheck { ...@@ -324,7 +324,7 @@ public class MapCheck {
++sum; ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == size); reallyAssert(sum == size);
} }
static void entest2(Hashtable ht, int size) { static void entest2(Hashtable ht, int size) {
...@@ -335,7 +335,7 @@ public class MapCheck { ...@@ -335,7 +335,7 @@ public class MapCheck {
++sum; ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == size); reallyAssert(sum == size);
} }
...@@ -349,7 +349,7 @@ public class MapCheck { ...@@ -349,7 +349,7 @@ public class MapCheck {
++sum; ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == size); reallyAssert(sum == size);
} }
static void entest4(Hashtable ht, int size) { static void entest4(Hashtable ht, int size) {
...@@ -361,7 +361,7 @@ public class MapCheck { ...@@ -361,7 +361,7 @@ public class MapCheck {
++sum; ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == size); reallyAssert(sum == size);
} }
static void entest(Map s, int size) { static void entest(Map s, int size) {
...@@ -409,13 +409,13 @@ public class MapCheck { ...@@ -409,13 +409,13 @@ public class MapCheck {
timer.start("Iter Equals ", size * 2); timer.start("Iter Equals ", size * 2);
boolean eqt = s2.equals(s) && s.equals(s2); boolean eqt = s2.equals(s) && s.equals(s2);
reallyAssert (eqt); reallyAssert(eqt);
timer.finish(); timer.finish();
timer.start("Iter HashCode ", size * 2); timer.start("Iter HashCode ", size * 2);
int shc = s.hashCode(); int shc = s.hashCode();
int s2hc = s2.hashCode(); int s2hc = s2.hashCode();
reallyAssert (shc == s2hc); reallyAssert(shc == s2hc);
timer.finish(); timer.finish();
timer.start("Put (present) ", size); timer.start("Put (present) ", size);
...@@ -430,7 +430,7 @@ public class MapCheck { ...@@ -430,7 +430,7 @@ public class MapCheck {
if (es2.contains(entry)) ++sum; if (es2.contains(entry)) ++sum;
} }
timer.finish(); timer.finish();
reallyAssert (sum == size); reallyAssert(sum == size);
t6("Get ", size, s2, key, absent); t6("Get ", size, s2, key, absent);
...@@ -438,13 +438,13 @@ public class MapCheck { ...@@ -438,13 +438,13 @@ public class MapCheck {
s2.put(key[size-1], absent[0]); s2.put(key[size-1], absent[0]);
timer.start("Iter Equals ", size * 2); timer.start("Iter Equals ", size * 2);
eqt = s2.equals(s) && s.equals(s2); eqt = s2.equals(s) && s.equals(s2);
reallyAssert (!eqt); reallyAssert(!eqt);
timer.finish(); timer.finish();
timer.start("Iter HashCode ", size * 2); timer.start("Iter HashCode ", size * 2);
int s1h = s.hashCode(); int s1h = s.hashCode();
int s2h = s2.hashCode(); int s2h = s2.hashCode();
reallyAssert (s1h != s2h); reallyAssert(s1h != s2h);
timer.finish(); timer.finish();
s2.put(key[size-1], hold); s2.put(key[size-1], hold);
...@@ -455,12 +455,12 @@ public class MapCheck { ...@@ -455,12 +455,12 @@ public class MapCheck {
es.remove(s2i.next()); es.remove(s2i.next());
timer.finish(); timer.finish();
reallyAssert (s.isEmpty()); reallyAssert(s.isEmpty());
timer.start("Clear ", size); timer.start("Clear ", size);
s2.clear(); s2.clear();
timer.finish(); timer.finish();
reallyAssert (s2.isEmpty() && s.isEmpty()); reallyAssert(s2.isEmpty() && s.isEmpty());
} }
static void stest(Map s, int size) throws Exception { static void stest(Map s, int size) throws Exception {
...@@ -489,7 +489,7 @@ public class MapCheck { ...@@ -489,7 +489,7 @@ public class MapCheck {
System.out.print(time + "ms"); System.out.print(time + "ms");
if (s instanceof IdentityHashMap) return; if (s instanceof IdentityHashMap) return;
reallyAssert (s.equals(m)); reallyAssert(s.equals(m));
} }
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
/* /*
* @test * @test
* @bug 4486658 * @bug 4486658
* @compile MapLoops.java * @compile -source 1.5 MapLoops.java
* @run main/timeout=1600 MapLoops * @run main/timeout=1600 MapLoops
* @summary Exercise multithreaded maps, by default ConcurrentHashMap. * @summary Exercise multithreaded maps, by default ConcurrentHashMap.
* Multithreaded hash table test. Each thread does a random walk * Multithreaded hash table test. Each thread does a random walk
...@@ -225,7 +225,7 @@ public class MapLoops { ...@@ -225,7 +225,7 @@ public class MapLoops {
barrier.await(); barrier.await();
} }
catch (Throwable throwable) { catch (Throwable throwable) {
synchronized(System.err) { synchronized (System.err) {
System.err.println("--------------------------------"); System.err.println("--------------------------------");
throwable.printStackTrace(); throwable.printStackTrace();
} }
......
...@@ -79,9 +79,9 @@ class LoopHelpers { ...@@ -79,9 +79,9 @@ class LoopHelpers {
* Basically same as java.util.Random. * Basically same as java.util.Random.
*/ */
public static class SimpleRandom { public static class SimpleRandom {
private final static long multiplier = 0x5DEECE66DL; private static final long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL; private static final long addend = 0xBL;
private final static long mask = (1L << 48) - 1; private static final long mask = (1L << 48) - 1;
static final AtomicLong seq = new AtomicLong(1); static final AtomicLong seq = new AtomicLong(1);
private long seed = System.nanoTime() + seq.getAndIncrement(); private long seed = System.nanoTime() + seq.getAndIncrement();
......
...@@ -66,7 +66,7 @@ public class EqualsRace { ...@@ -66,7 +66,7 @@ public class EqualsRace {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class CheckedThread extends Thread { private abstract static class CheckedThread extends Thread {
public abstract void realRun() throws Throwable; public abstract void realRun() throws Throwable;
public void run() { public void run() {
try { realRun(); } catch (Throwable t) { unexpected(t); }}} try { realRun(); } catch (Throwable t) { unexpected(t); }}}
......
...@@ -125,7 +125,7 @@ public class RacingCows { ...@@ -125,7 +125,7 @@ public class RacingCows {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class CheckedThread extends Thread { private abstract static class CheckedThread extends Thread {
public abstract void realRun() throws Throwable; public abstract void realRun() throws Throwable;
public void run() { public void run() {
try { realRun(); } catch (Throwable t) { unexpected(t); }}} try { realRun(); } catch (Throwable t) { unexpected(t); }}}
......
...@@ -83,7 +83,7 @@ public class Basic { ...@@ -83,7 +83,7 @@ public class Basic {
//---------------------------------------------------------------- //----------------------------------------------------------------
// Convenience methods for creating threads that call CyclicBarrier.await // Convenience methods for creating threads that call CyclicBarrier.await
//---------------------------------------------------------------- //----------------------------------------------------------------
private static abstract class Awaiter extends Thread { private abstract static class Awaiter extends Thread {
static AtomicInteger count = new AtomicInteger(1); static AtomicInteger count = new AtomicInteger(1);
{ {
...@@ -417,14 +417,14 @@ public class Basic { ...@@ -417,14 +417,14 @@ public class Basic {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
static abstract class Fun { abstract void f() throws Throwable; } abstract static class Fun { abstract void f() throws Throwable; }
private static void THROWS(Class<? extends Throwable> k, Fun... fs) { private static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
catch (Throwable t) { catch (Throwable t) {
if (k.isAssignableFrom(t.getClass())) pass(); if (k.isAssignableFrom(t.getClass())) pass();
else unexpected(t);}} else unexpected(t);}}
private static abstract class CheckedThread extends Thread { private abstract static class CheckedThread extends Thread {
abstract void realRun() throws Throwable; abstract void realRun() throws Throwable;
public void run() { public void run() {
try {realRun();} catch (Throwable t) {unexpected(t);}}} try {realRun();} catch (Throwable t) {unexpected(t);}}}
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
/* /*
* @test * @test
* @bug 4486658 * @bug 4486658
* @compile ExchangeLoops.java * @compile -source 1.5 ExchangeLoops.java
* @run main/timeout=720 ExchangeLoops * @run main/timeout=720 ExchangeLoops
* @summary checks to make sure a pipeline of exchangers passes data. * @summary checks to make sure a pipeline of exchangers passes data.
*/ */
...@@ -78,9 +78,9 @@ public class ExchangeLoops { ...@@ -78,9 +78,9 @@ public class ExchangeLoops {
final Exchanger<Int> right; final Exchanger<Int> right;
final CyclicBarrier barrier; final CyclicBarrier barrier;
volatile int result; volatile int result;
Stage (Exchanger<Int> left, Stage(Exchanger<Int> left,
Exchanger<Int> right, Exchanger<Int> right,
CyclicBarrier b, int iters) { CyclicBarrier b, int iters) {
this.left = left; this.left = left;
this.right = right; this.right = right;
barrier = b; barrier = b;
......
...@@ -78,9 +78,9 @@ class LoopHelpers { ...@@ -78,9 +78,9 @@ class LoopHelpers {
* Basically same as java.util.Random. * Basically same as java.util.Random.
*/ */
public static class SimpleRandom { public static class SimpleRandom {
private final static long multiplier = 0x5DEECE66DL; private static final long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL; private static final long addend = 0xBL;
private final static long mask = (1L << 48) - 1; private static final long mask = (1L << 48) - 1;
static final AtomicLong seq = new AtomicLong(1); static final AtomicLong seq = new AtomicLong(1);
private long seed = System.nanoTime() + seq.getAndIncrement(); private long seed = System.nanoTime() + seq.getAndIncrement();
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
/* /*
* @test * @test
* @bug 4965960 * @bug 4965960
* @compile ExecutorCompletionServiceLoops.java * @compile -source 1.5 ExecutorCompletionServiceLoops.java
* @run main/timeout=3600 ExecutorCompletionServiceLoops * @run main/timeout=3600 ExecutorCompletionServiceLoops
* @summary Exercise ExecutorCompletionServiceLoops * @summary Exercise ExecutorCompletionServiceLoops
*/ */
......
...@@ -78,9 +78,9 @@ class LoopHelpers { ...@@ -78,9 +78,9 @@ class LoopHelpers {
* Basically same as java.util.Random. * Basically same as java.util.Random.
*/ */
public static class SimpleRandom { public static class SimpleRandom {
private final static long multiplier = 0x5DEECE66DL; private static final long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL; private static final long addend = 0xBL;
private final static long mask = (1L << 48) - 1; private static final long mask = (1L << 48) - 1;
static final AtomicLong seq = new AtomicLong(1); static final AtomicLong seq = new AtomicLong(1);
private long seed = System.nanoTime() + seq.getAndIncrement(); private long seed = System.nanoTime() + seq.getAndIncrement();
......
...@@ -122,7 +122,7 @@ public class Throws { ...@@ -122,7 +122,7 @@ public class Throws {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class Fun {abstract void f() throws Throwable;} private abstract static class Fun {abstract void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) { static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
...@@ -87,7 +87,7 @@ public class BlockingTaskExecutor { ...@@ -87,7 +87,7 @@ public class BlockingTaskExecutor {
* A helper class with a method to wait for a notification. * A helper class with a method to wait for a notification.
* *
* The notification is received via the * The notification is received via the
* <code>sendNotification</code> method. * {@code sendNotification} method.
*/ */
static class NotificationReceiver { static class NotificationReceiver {
/** Has the notifiee been notified? */ /** Has the notifiee been notified? */
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
/* /*
* @test * @test
* @bug 4486658 * @bug 4486658
* @compile CancelledFutureLoops.java * @compile -source 1.5 CancelledFutureLoops.java
* @run main/timeout=2000 CancelledFutureLoops * @run main/timeout=2000 CancelledFutureLoops
* @summary Checks for responsiveness of futures to cancellation. * @summary Checks for responsiveness of futures to cancellation.
* Runs under the assumption that ITERS computations require more than * Runs under the assumption that ITERS computations require more than
...@@ -64,10 +64,10 @@ public final class CancelledFutureLoops { ...@@ -64,10 +64,10 @@ public final class CancelledFutureLoops {
try { try {
new FutureLoop(i).test(); new FutureLoop(i).test();
} }
catch(BrokenBarrierException bb) { catch (BrokenBarrierException bb) {
// OK; ignore // OK; ignore
} }
catch(ExecutionException ee) { catch (ExecutionException ee) {
// OK; ignore // OK; ignore
} }
Thread.sleep(TIMEOUT); Thread.sleep(TIMEOUT);
......
...@@ -203,7 +203,7 @@ public class Customized { ...@@ -203,7 +203,7 @@ public class Customized {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class Fun {abstract void f() throws Throwable;} private abstract static class Fun {abstract void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) { static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
...@@ -78,9 +78,9 @@ class LoopHelpers { ...@@ -78,9 +78,9 @@ class LoopHelpers {
* Basically same as java.util.Random. * Basically same as java.util.Random.
*/ */
public static class SimpleRandom { public static class SimpleRandom {
private final static long multiplier = 0x5DEECE66DL; private static final long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL; private static final long addend = 0xBL;
private final static long mask = (1L << 48) - 1; private static final long mask = (1L << 48) - 1;
static final AtomicLong seq = new AtomicLong(1); static final AtomicLong seq = new AtomicLong(1);
private long seed = System.nanoTime() + seq.getAndIncrement(); private long seed = System.nanoTime() + seq.getAndIncrement();
......
...@@ -161,11 +161,8 @@ public class DelayOverflow { ...@@ -161,11 +161,8 @@ public class DelayOverflow {
if (x == null ? y == null : x.equals(y)) pass(); if (x == null ? y == null : x.equals(y)) pass();
else fail(x + " not equal to " + y);} else fail(x + " not equal to " + y);}
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
Class<?> k = new Object(){}.getClass().getEnclosingClass(); new DelayOverflow().instanceMain(args);}
try {k.getMethod("instanceMain",String[].class) void instanceMain(String[] args) throws Throwable {
.invoke( k.newInstance(), (Object) args);}
catch (Throwable e) {throw e.getCause();}}
public void instanceMain(String[] args) throws Throwable {
try {test(args);} catch (Throwable t) {unexpected(t);} try {test(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
......
...@@ -36,9 +36,9 @@ import java.util.concurrent.atomic.*; ...@@ -36,9 +36,9 @@ import java.util.concurrent.atomic.*;
import static java.util.concurrent.TimeUnit.*; import static java.util.concurrent.TimeUnit.*;
public class ConfigChanges { public class ConfigChanges {
final static ThreadGroup tg = new ThreadGroup("pool"); static final ThreadGroup tg = new ThreadGroup("pool");
final static Random rnd = new Random(); static final Random rnd = new Random();
static void report(ThreadPoolExecutor tpe) { static void report(ThreadPoolExecutor tpe) {
try { try {
...@@ -241,7 +241,7 @@ public class ConfigChanges { ...@@ -241,7 +241,7 @@ public class ConfigChanges {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class Fun {abstract void f() throws Throwable;} private abstract static class Fun {abstract void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) { static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
......
...@@ -43,7 +43,7 @@ public class Custom { ...@@ -43,7 +43,7 @@ public class Custom {
private static class CustomTask<V> extends FutureTask<V> { private static class CustomTask<V> extends FutureTask<V> {
public final static AtomicInteger births = new AtomicInteger(0); public static final AtomicInteger births = new AtomicInteger(0);
CustomTask(Callable<V> c) { super(c); births.getAndIncrement(); } CustomTask(Callable<V> c) { super(c); births.getAndIncrement(); }
CustomTask(Runnable r, V v) { super(r, v); births.getAndIncrement(); } CustomTask(Runnable r, V v) { super(r, v); births.getAndIncrement(); }
} }
...@@ -63,7 +63,7 @@ public class Custom { ...@@ -63,7 +63,7 @@ public class Custom {
} }
private static class CustomSTPE extends ScheduledThreadPoolExecutor { private static class CustomSTPE extends ScheduledThreadPoolExecutor {
public final static AtomicInteger decorations = new AtomicInteger(0); public static final AtomicInteger decorations = new AtomicInteger(0);
CustomSTPE() { CustomSTPE() {
super(threadCount); super(threadCount);
} }
...@@ -89,7 +89,7 @@ public class Custom { ...@@ -89,7 +89,7 @@ public class Custom {
return count; return count;
} }
private final static int threadCount = 10; private static final int threadCount = 10;
public static void main(String[] args) throws Throwable { public static void main(String[] args) throws Throwable {
CustomTPE tpe = new CustomTPE(); CustomTPE tpe = new CustomTPE();
......
...@@ -37,10 +37,10 @@ public class ScheduledTickleService { ...@@ -37,10 +37,10 @@ public class ScheduledTickleService {
// We get intermittent ClassCastException if greater than 1 // We get intermittent ClassCastException if greater than 1
// because of calls to compareTo // because of calls to compareTo
private final static int concurrency = 2; private static final int concurrency = 2;
// Record when tasks are done // Record when tasks are done
public final static CountDownLatch done = new CountDownLatch(concurrency); public static final CountDownLatch done = new CountDownLatch(concurrency);
public static void realMain(String... args) throws InterruptedException { public static void realMain(String... args) throws InterruptedException {
// our tickle service // our tickle service
......
...@@ -40,7 +40,7 @@ public class ShutdownNowExecuteRace { ...@@ -40,7 +40,7 @@ public class ShutdownNowExecuteRace {
static volatile boolean quit = false; static volatile boolean quit = false;
static volatile ThreadPoolExecutor pool = null; static volatile ThreadPoolExecutor pool = null;
final static Runnable sleeper = new Runnable() { public void run() { static final Runnable sleeper = new Runnable() { public void run() {
final long ONE_HOUR = 1000L * 60L * 60L; final long ONE_HOUR = 1000L * 60L * 60L;
try { Thread.sleep(ONE_HOUR); } try { Thread.sleep(ONE_HOUR); }
catch (InterruptedException ie) {} catch (InterruptedException ie) {}
...@@ -81,14 +81,14 @@ public class ShutdownNowExecuteRace { ...@@ -81,14 +81,14 @@ public class ShutdownNowExecuteRace {
try {realMain(args);} catch (Throwable t) {unexpected(t);} try {realMain(args);} catch (Throwable t) {unexpected(t);}
System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
if (failed > 0) throw new AssertionError("Some tests failed");} if (failed > 0) throw new AssertionError("Some tests failed");}
private static abstract class Fun {abstract void f() throws Throwable;} private abstract static class Fun {abstract void f() throws Throwable;}
static void THROWS(Class<? extends Throwable> k, Fun... fs) { static void THROWS(Class<? extends Throwable> k, Fun... fs) {
for (Fun f : fs) for (Fun f : fs)
try { f.f(); fail("Expected " + k.getName() + " not thrown"); } try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
catch (Throwable t) { catch (Throwable t) {
if (k.isAssignableFrom(t.getClass())) pass(); if (k.isAssignableFrom(t.getClass())) pass();
else unexpected(t);}} else unexpected(t);}}
private static abstract class CheckedThread extends Thread { private abstract static class CheckedThread extends Thread {
abstract void realRun() throws Throwable; abstract void realRun() throws Throwable;
public void run() { public void run() {
try {realRun();} catch (Throwable t) {unexpected(t);}}} try {realRun();} catch (Throwable t) {unexpected(t);}}}
......
...@@ -35,7 +35,7 @@ import java.util.concurrent.*; ...@@ -35,7 +35,7 @@ import java.util.concurrent.*;
import java.util.concurrent.atomic.*; import java.util.concurrent.atomic.*;
public class ThrowingTasks { public class ThrowingTasks {
final static Random rnd = new Random(); static final Random rnd = new Random();
@SuppressWarnings("serial") @SuppressWarnings("serial")
static class UncaughtExceptions static class UncaughtExceptions
...@@ -65,16 +65,16 @@ public class ThrowingTasks { ...@@ -65,16 +65,16 @@ public class ThrowingTasks {
} }
} }
final static UncaughtExceptions uncaughtExceptions static final UncaughtExceptions uncaughtExceptions
= new UncaughtExceptions(); = new UncaughtExceptions();
final static UncaughtExceptionsTable uncaughtExceptionsTable static final UncaughtExceptionsTable uncaughtExceptionsTable
= new UncaughtExceptionsTable(); = new UncaughtExceptionsTable();
final static AtomicLong totalUncaughtExceptions static final AtomicLong totalUncaughtExceptions
= new AtomicLong(0); = new AtomicLong(0);
final static CountDownLatch uncaughtExceptionsLatch static final CountDownLatch uncaughtExceptionsLatch
= new CountDownLatch(24); = new CountDownLatch(24);
final static Thread.UncaughtExceptionHandler handler static final Thread.UncaughtExceptionHandler handler
= new Thread.UncaughtExceptionHandler() { = new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) { public void uncaughtException(Thread t, Throwable e) {
check(! Thread.currentThread().isInterrupted()); check(! Thread.currentThread().isInterrupted());
...@@ -84,19 +84,19 @@ public class ThrowingTasks { ...@@ -84,19 +84,19 @@ public class ThrowingTasks {
uncaughtExceptionsLatch.countDown(); uncaughtExceptionsLatch.countDown();
}}; }};
final static ThreadGroup tg = new ThreadGroup("Flaky"); static final ThreadGroup tg = new ThreadGroup("Flaky");
final static ThreadFactory tf = new ThreadFactory() { static final ThreadFactory tf = new ThreadFactory() {
public Thread newThread(Runnable r) { public Thread newThread(Runnable r) {
Thread t = new Thread(tg, r); Thread t = new Thread(tg, r);
t.setUncaughtExceptionHandler(handler); t.setUncaughtExceptionHandler(handler);
return t; return t;
}}; }};
final static RuntimeException rte = new RuntimeException(); static final RuntimeException rte = new RuntimeException();
final static Error error = new Error(); static final Error error = new Error();
final static Throwable weird = new Throwable(); static final Throwable weird = new Throwable();
final static Exception checkedException = new Exception(); static final Exception checkedException = new Exception();
static class Thrower implements Runnable { static class Thrower implements Runnable {
Throwable t; Throwable t;
...@@ -105,13 +105,13 @@ public class ThrowingTasks { ...@@ -105,13 +105,13 @@ public class ThrowingTasks {
public void run() { if (t != null) Thread.currentThread().stop(t); } public void run() { if (t != null) Thread.currentThread().stop(t); }
} }
final static Thrower noThrower = new Thrower(null); static final Thrower noThrower = new Thrower(null);
final static Thrower rteThrower = new Thrower(rte); static final Thrower rteThrower = new Thrower(rte);
final static Thrower errorThrower = new Thrower(error); static final Thrower errorThrower = new Thrower(error);
final static Thrower weirdThrower = new Thrower(weird); static final Thrower weirdThrower = new Thrower(weird);
final static Thrower checkedThrower = new Thrower(checkedException); static final Thrower checkedThrower = new Thrower(checkedException);
final static List<Thrower> throwers = Arrays.asList( static final List<Thrower> throwers = Arrays.asList(
noThrower, rteThrower, errorThrower, weirdThrower, checkedThrower); noThrower, rteThrower, errorThrower, weirdThrower, checkedThrower);
static class Flaky implements Runnable { static class Flaky implements Runnable {
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
/* /*
* @test * @test
* @bug 4992443 4994819 * @bug 4992443 4994819
* @compile -source 1.5 VMSupportsCS8.java
* @run main VMSupportsCS8
* @summary Checks that the value of VMSupportsCS8 matches system properties. * @summary Checks that the value of VMSupportsCS8 matches system properties.
*/ */
......
...@@ -75,10 +75,10 @@ public class FlakyMutex implements Lock { ...@@ -75,10 +75,10 @@ public class FlakyMutex implements Lock {
catch (Throwable t) { checkThrowable(t); } catch (Throwable t) { checkThrowable(t); }
} }
try { check (! m.tryLock()); } try { check(! m.tryLock()); }
catch (Throwable t) { checkThrowable(t); } catch (Throwable t) { checkThrowable(t); }
try { check (! m.tryLock(1, TimeUnit.MICROSECONDS)); } try { check(! m.tryLock(1, TimeUnit.MICROSECONDS)); }
catch (Throwable t) { checkThrowable(t); } catch (Throwable t) { checkThrowable(t); }
m.unlock(); m.unlock();
......
...@@ -64,7 +64,7 @@ public class TimedAcquireLeak { ...@@ -64,7 +64,7 @@ public class TimedAcquireLeak {
return outputOf(new InputStreamReader(is, "UTF-8")); return outputOf(new InputStreamReader(is, "UTF-8"));
} }
final static ExecutorService drainers = Executors.newFixedThreadPool(12); static final ExecutorService drainers = Executors.newFixedThreadPool(12);
static Future<String> futureOutputOf(final InputStream is) { static Future<String> futureOutputOf(final InputStream is) {
return drainers.submit( return drainers.submit(
new Callable<String>() { public String call() throws IOException { new Callable<String>() { public String call() throws IOException {
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
/* /*
* @test * @test
* @bug 4486658 * @bug 4486658
* @compile CancelledLockLoops.java * @compile -source 1.5 CancelledLockLoops.java
* @run main/timeout=2800 CancelledLockLoops * @run main/timeout=2800 CancelledLockLoops
* @summary tests lockInterruptibly. * @summary tests lockInterruptibly.
* Checks for responsiveness of locks to interrupts. Runs under that * Checks for responsiveness of locks to interrupts. Runs under that
...@@ -64,7 +64,7 @@ public final class CancelledLockLoops { ...@@ -64,7 +64,7 @@ public final class CancelledLockLoops {
try { try {
new ReentrantLockLoop(i).test(); new ReentrantLockLoop(i).test();
} }
catch(BrokenBarrierException bb) { catch (BrokenBarrierException bb) {
// OK, ignore // OK, ignore
} }
Thread.sleep(TIMEOUT); Thread.sleep(TIMEOUT);
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
/* /*
* @test * @test
* @bug 4486658 * @bug 4486658
* @compile LockOncePerThreadLoops.java * @compile -source 1.5 LockOncePerThreadLoops.java
* @run main/timeout=15000 LockOncePerThreadLoops * @run main/timeout=15000 LockOncePerThreadLoops
* @summary Checks for missed signals by locking and unlocking each of an array of locks once per thread * @summary Checks for missed signals by locking and unlocking each of an array of locks once per thread
*/ */
......
...@@ -78,9 +78,9 @@ class LoopHelpers { ...@@ -78,9 +78,9 @@ class LoopHelpers {
* Basically same as java.util.Random. * Basically same as java.util.Random.
*/ */
public static class SimpleRandom { public static class SimpleRandom {
private final static long multiplier = 0x5DEECE66DL; private static final long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL; private static final long addend = 0xBL;
private final static long mask = (1L << 48) - 1; private static final long mask = (1L << 48) - 1;
static final AtomicLong seq = new AtomicLong(1); static final AtomicLong seq = new AtomicLong(1);
private long seed = System.nanoTime() + seq.getAndIncrement(); private long seed = System.nanoTime() + seq.getAndIncrement();
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
/* /*
* @test * @test
* @bug 4486658 * @bug 4486658
* @compile SimpleReentrantLockLoops.java * @compile -source 1.5 SimpleReentrantLockLoops.java
* @run main/timeout=4500 SimpleReentrantLockLoops * @run main/timeout=4500 SimpleReentrantLockLoops
* @summary multiple threads using a single lock * @summary multiple threads using a single lock
*/ */
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
/* /*
* @test * @test
* @bug 4486658 5031862 * @bug 4486658 5031862
* @compile -source 1.5 TimeoutLockLoops.java
* @run main TimeoutLockLoops
* @summary Checks for responsiveness of locks to timeouts. * @summary Checks for responsiveness of locks to timeouts.
* Runs under the assumption that ITERS computations require more than * Runs under the assumption that ITERS computations require more than
* TIMEOUT msecs to complete, which seems to be a safe assumption for * TIMEOUT msecs to complete, which seems to be a safe assumption for
......
...@@ -45,7 +45,7 @@ public class Bug6571733 { ...@@ -45,7 +45,7 @@ public class Bug6571733 {
Thread thread = new Thread() { public void run() { Thread thread = new Thread() { public void run() {
try { try {
check (! lock.writeLock().tryLock(0, TimeUnit.DAYS)); check(! lock.writeLock().tryLock(0, TimeUnit.DAYS));
lock.readLock().lock(); lock.readLock().lock();
lock.readLock().unlock(); lock.readLock().unlock();
......
...@@ -78,9 +78,9 @@ class LoopHelpers { ...@@ -78,9 +78,9 @@ class LoopHelpers {
* Basically same as java.util.Random. * Basically same as java.util.Random.
*/ */
public static class SimpleRandom { public static class SimpleRandom {
private final static long multiplier = 0x5DEECE66DL; private static final long multiplier = 0x5DEECE66DL;
private final static long addend = 0xBL; private static final long addend = 0xBL;
private final static long mask = (1L << 48) - 1; private static final long mask = (1L << 48) - 1;
static final AtomicLong seq = new AtomicLong(1); static final AtomicLong seq = new AtomicLong(1);
private long seed = System.nanoTime() + seq.getAndIncrement(); private long seed = System.nanoTime() + seq.getAndIncrement();
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
/* /*
* @test * @test
* @bug 4486658 * @bug 4486658
* @compile MapLoops.java * @compile -source 1.5 MapLoops.java
* @run main/timeout=4700 MapLoops * @run main/timeout=4700 MapLoops
* @summary Exercise multithreaded maps, by default ConcurrentHashMap. * @summary Exercise multithreaded maps, by default ConcurrentHashMap.
* Multithreaded hash table test. Each thread does a random walk * Multithreaded hash table test. Each thread does a random walk
...@@ -65,7 +65,7 @@ public class MapLoops { ...@@ -65,7 +65,7 @@ public class MapLoops {
if (args.length > 0) { if (args.length > 0) {
try { try {
mapClass = Class.forName(args[0]); mapClass = Class.forName(args[0]);
} catch(ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new RuntimeException("Class " + args[0] + " not found."); throw new RuntimeException("Class " + args[0] + " not found.");
} }
} }
......
...@@ -57,21 +57,33 @@ public class RWMap implements Map { ...@@ -57,21 +57,33 @@ public class RWMap implements Map {
} }
public int size() { public int size() {
rwl.readLock().lock(); try {return m.size();} finally { rwl.readLock().unlock(); } rwl.readLock().lock();
try { return m.size(); }
finally { rwl.readLock().unlock(); }
} }
public boolean isEmpty(){
rwl.readLock().lock(); try {return m.isEmpty();} finally { rwl.readLock().unlock(); } public boolean isEmpty() {
rwl.readLock().lock();
try { return m.isEmpty(); }
finally { rwl.readLock().unlock(); }
} }
public Object get(Object key) { public Object get(Object key) {
rwl.readLock().lock(); try {return m.get(key);} finally { rwl.readLock().unlock(); } rwl.readLock().lock();
try { return m.get(key); }
finally { rwl.readLock().unlock(); }
} }
public boolean containsKey(Object key) { public boolean containsKey(Object key) {
rwl.readLock().lock(); try {return m.containsKey(key);} finally { rwl.readLock().unlock(); } rwl.readLock().lock();
try { return m.containsKey(key); }
finally { rwl.readLock().unlock(); }
} }
public boolean containsValue(Object value){
rwl.readLock().lock(); try {return m.containsValue(value);} finally { rwl.readLock().unlock(); } public boolean containsValue(Object value) {
rwl.readLock().lock();
try { return m.containsValue(value); }
finally { rwl.readLock().unlock(); }
} }
...@@ -88,28 +100,45 @@ public class RWMap implements Map { ...@@ -88,28 +100,45 @@ public class RWMap implements Map {
} }
public boolean equals(Object o) { public boolean equals(Object o) {
rwl.readLock().lock(); try {return m.equals(o);} finally { rwl.readLock().unlock(); } rwl.readLock().lock();
try { return m.equals(o); }
finally { rwl.readLock().unlock(); }
} }
public int hashCode() { public int hashCode() {
rwl.readLock().lock(); try {return m.hashCode();} finally { rwl.readLock().unlock(); } rwl.readLock().lock();
try { return m.hashCode(); }
finally { rwl.readLock().unlock(); }
} }
public String toString() { public String toString() {
rwl.readLock().lock(); try {return m.toString();} finally { rwl.readLock().unlock(); } rwl.readLock().lock();
try { return m.toString(); }
finally { rwl.readLock().unlock(); }
} }
public Object put(Object key, Object value) { public Object put(Object key, Object value) {
rwl.writeLock().lock(); try {return m.put(key, value);} finally { rwl.writeLock().unlock(); } rwl.writeLock().lock();
try { return m.put(key, value); }
finally { rwl.writeLock().unlock(); }
} }
public Object remove(Object key) { public Object remove(Object key) {
rwl.writeLock().lock(); try {return m.remove(key);} finally { rwl.writeLock().unlock(); } rwl.writeLock().lock();
try { return m.remove(key); }
finally { rwl.writeLock().unlock(); }
} }
public void putAll(Map map) { public void putAll(Map map) {
rwl.writeLock().lock(); try {m.putAll(map);} finally { rwl.writeLock().unlock(); } rwl.writeLock().lock();
try { m.putAll(map); }
finally { rwl.writeLock().unlock(); }
} }
public void clear() { public void clear() {
rwl.writeLock().lock(); try {m.clear();} finally { rwl.writeLock().unlock(); } rwl.writeLock().lock();
try { m.clear(); }
finally { rwl.writeLock().unlock(); }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册