Java 5 provides concurrent1_queue to simplify concurrent operations. However, there is a problem: does it mean that we do not need to perform any synchronization or lock operations on our own after using this class?
I found this online: http://stackoverflow.com/questions/435069/java-util-concurrentlinkedqueue/435941 // stackoverflow is really a good place ......
That is to say, if you directly use the functions provided by it, such as queue. Add (OBJ); or queue. Poll (OBJ);, we do not need to perform any synchronization on our own. However, if it is a non-atomic operation, for example:
If (! Queue. isempty () {<br/> queue. Poll (OBJ); <br/>}
It is hard to ensure that this queue is not modified by other threads before poll () after isempty () is called. So in this case, we still need to synchronize ourselves:
Synchronized (Queue) {<br/> If (! Queue. isempty () {<br/> queue. Poll (OBJ); <br/>}< br/>}