You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by "Ramkumar Ramalingam (JIRA)" <tu...@ws.apache.org> on 2008/04/09 13:41:24 UTC
[jira] Commented: (TUSCANY-2092) ConcurrentModificationException in
ExtensibleContributionListener
[ https://issues.apache.org/jira/browse/TUSCANY-2092?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12587149#action_12587149 ]
Ramkumar Ramalingam commented on TUSCANY-2092:
----------------------------------------------
Using Vectors OR Collections.synchronizedList for listeners synchronizes your list object. However, the iterators implemented in the java.util Collections classes are fail-fast, which means that if one thread changes a collection while another thread is traversing it through an Iterator, the next Iterator.hasNext() or Iterator.next() call will throw ConcurrentModificationException. If we have to prevent ConcurrentModificationException, we must lock the entire List while you are iterating by wrapping it with a synchronized block, which inturn is costly.
A better solution to the above problem seems to be, the CopyOnWriteArrayList class from util.concurrent (which will also appear in the java.util.concurrent package in JDK 1.5) is a thread-safe implementation of ArrayList that offers far better concurrency. Multiple reads can almost always execute concurrently, simultaneous reads and writes can usually execute concurrently, and multiple simultaneous writes can often execute concurrently. Also CopyOnWriteArrayList contains a mutable reference to an immutable array, so as long as that reference is held fixed, you get all the thread-safety benefits of immutability without the need for locking.
I have attached a patch using the above solution to this issue.
> ConcurrentModificationException in ExtensibleContributionListener
> -----------------------------------------------------------------
>
> Key: TUSCANY-2092
> URL: https://issues.apache.org/jira/browse/TUSCANY-2092
> Project: Tuscany
> Issue Type: Bug
> Reporter: Greg Dritschler
> Assignee: Ramkumar Ramalingam
> Attachments: JIRA-2092.patch
>
>
> java.util.ConcurrentModificationException
> at java.util.AbstractList$SimpleListIterator.next(Unknown Source)
> at org.apache.tuscany.sca.contribution.service.ExtensibleContributionListener.contributionAdded(ExtensibleContributionListener.java:40)
> at org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl.addContribution(ContributionServiceImpl.java:389)
> at org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl.contribute(ContributionServiceImpl.java:202)
> The problem occurs if two threads try to add a contribution simultaneously.
> DefaultContributionListenerExtensionPoint does not synchronize the list of listeners. In particular loadListeners does not prevent multiple threads from trying to load the list of listeners. One thread completes first while the other is still loading. This leads to the exception shown above when a thread tries to iterate the listener list.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org