8343250: ArrayBlockingQueue serialization not thread safe
Reviewed-by: rriggs, alanb
This commit is contained in:
parent
2c1e4c3816
commit
5729227651
@ -35,6 +35,7 @@
|
||||
|
||||
package java.util.concurrent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.AbstractQueue;
|
||||
import java.util.Arrays;
|
||||
@ -1617,6 +1618,23 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
|
||||
&& (count == 0 || items[dec(putIndex, capacity)] != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the queue to the stream whilst holding the locks to prevent
|
||||
* broken invariants.
|
||||
*
|
||||
* @param s the stream
|
||||
* @throws java.io.IOException if an I/O error occurs
|
||||
*/
|
||||
private void writeObject(java.io.ObjectOutputStream s) throws IOException {
|
||||
final ReentrantLock lock = this.lock;
|
||||
lock.lock();
|
||||
try {
|
||||
s.defaultWriteObject();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconstitutes this queue from a stream (that is, deserializes it).
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user