tag:blogger.com,1999:blog-36773632.post2748153945716181791..comments2023-12-19T08:40:05.062-05:00Comments on Java Evangelist John Yeary: Threaded Queue Example - ConcurrentLinkedQueueJohn Yearyhttp://www.blogger.com/profile/00461192445071361043noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-36773632.post-37626671984001653572012-05-14T08:08:56.784-05:002012-05-14T08:08:56.784-05:00An interesting observation.
The current implement...An interesting observation.<br /><br />The current implementation does use a thread safe queue, but not all implementations of <i>Queue<T></i> are thread safe. <br /><br />The example is for general threads not specifically the use of <i>ConcurrentLinkedQueue<T></i>. <br /><br />If you look at <i>LinkedList<T></i> you will notice that the API suggests you use <i>Collections.synchronizedList(List<T> list)</i>, or external synchronization methods like the one in this example.<br /><br />I will concede that this is not the optimal use of <i>ConcurrentLinkedQueue<T></i> since it is already thread safe. You could remove the <i>synchronization</i> blocks.John Yearyhttps://www.blogger.com/profile/00461192445071361043noreply@blogger.comtag:blogger.com,1999:blog-36773632.post-89872384416380024992012-05-13T14:07:42.842-05:002012-05-13T14:07:42.842-05:00Why are you sychronizing on the queue at all? A Co...Why are you sychronizing on the queue at all? A ConcurrentLinkedQueue by design allows threads to concurrently access it without synchronization by using a 'no-wait' algorithm incorporating sophisticated techniques. Read the Javadoc or better yet, Brian Goetz's Java Concurrency in Practice for a good explanation.Pedro Estradahttps://www.blogger.com/profile/02514075150463992051noreply@blogger.comtag:blogger.com,1999:blog-36773632.post-48655738093638634262011-05-23T10:35:49.087-05:002011-05-23T10:35:49.087-05:00I had a correction from a colleague at work to che...I had a correction from a colleague at work to check to see if the Consumer got a null message before calling toString() on it. Nice catch, and an example of the power of free software and more eyes.John Yearyhttps://www.blogger.com/profile/00461192445071361043noreply@blogger.comtag:blogger.com,1999:blog-36773632.post-13962240070452279182011-05-23T08:56:50.457-05:002011-05-23T08:56:50.457-05:00ConcurrentLinkedQueue - a class I had not used bef...ConcurrentLinkedQueue - a class I had not used before. Thanks for sharing!mgoblue62https://www.blogger.com/profile/02113234422330280708noreply@blogger.com