[ 
https://issues.apache.org/jira/browse/TUSCANY-2085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12587156#action_12587156
 ] 

Ramkumar Ramalingam commented on TUSCANY-2085:
----------------------------------------------

To prevent ConcurrentModificationException, one way is to lock the entire List 
while you are iterating by wrapping it with a synchronized block, which inturn 
looks costly as the this would block the other thread to access the list for 
reading.

A better solution i would consider for the above problem would be, using 
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.

The code change required would be just to replace the ArrayList with 
CopyOnWriteArrayList:

private final List<DataBinding> databindings = new 
CopyOnWriteArrayList<DataBinding>();

> ConcurentModExc in DefaultDataBindingExtensionPoint 
> ----------------------------------------------------
>
>                 Key: TUSCANY-2085
>                 URL: https://issues.apache.org/jira/browse/TUSCANY-2085
>             Project: Tuscany
>          Issue Type: Bug
>          Components: Java SCA Data Binding Runtime
>    Affects Versions: Java-SCA-1.1
>            Reporter: Scott Kurz
>            Priority: Minor
>             Fix For: Java-SCA-Next
>
>         Attachments: 2085.patch
>
>
> Get an exception like the following, 
> java.util.ConcurrentModificationException
> at java.util.AbstractList$SimpleListIterator.next(Unknown Source)at 
> org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint.introspectType(DefaultDataBindingExtensionPoint.java:223)
> at 
> org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSFaultExceptionMapper.introspectFaultDataType(JAXWSFaultExceptionMapper.java:214)
> at 
> org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor.introspectFaultTypes(JAXWSJavaInterfaceProcessor.java:178)
> at 
> org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor.visitInterface(JAXWSJavaInterfaceProcessor.java:90)
> at 
> org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceIntrospectorImpl.introspectInterface(JavaInterfaceIntrospectorImpl.java:91)
> as this thread, A, is in a for-loop looping through 'databindings'
>  public boolean introspectType(DataType dataType, Annotation[] annotations, 
> boolean isException) {
>         loadDataBindings();
>         for (DataBinding binding : databindings) {
> while another thread, B, is still in loadDataBindings() and is still adding 
> to the databindings ArrayList.
> I'm working around this by putting a lock around the whole body  of 
> loadDataBindings()
>     private final byte[] loadingLock = new byte[0];
>     ...
>     private void loadDataBindings() {
>         synchronized (loadingLock) {
>             if (loadedDataBindings)
>                 return;
>            ...
>        }
>    }
> Another option might be to change addDataBinding() to look at the 'bindings' 
> Map before adding to 'databindings'.   
> I'll attach a patch and leave it for a second opinion.  

-- 
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to