3 Replies Latest reply on Mar 27, 2013 10:56 AM by Iryna Fedartsova

    ConcurrentModificationException in TimedCachePolicy

    Iryna Fedartsova Newbie

      I have application runnuing under JBoss AS 5.1. (2.2.16.GA)

      Two concurrent threads create the JavaMailSenderImpl objects at the same time. Aboute once a day it ends up with the ConcurrentModificationException. According to my investigation this exception is caused by the TimedCachePolicy object. It has the map of cached objects. And this map can be either thread safe or not depending on the threadSafe flag. In my case the flag is set to false and consequently the map is not thread safe. As a result it allows for my two threads use it concurrently. 

       

      So the question is: How can I make it thread safe? Is there some specific settings which I can set to true?

       

      It is the stack trace:

       

      at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)

               at java.util.HashMap$EntryIterator.next(HashMap.java:834)

               at java.util.HashMap$EntryIterator.next(HashMap.java:832)

               at org.jboss.util.TimedCachePolicy.getValidKeys(TimedCachePolicy.java:364)

               at org.jboss.virtual.plugins.cache.IterableTimedVFSCache.findContext(IterableTimedVFSCache.java:65)

               at org.jboss.virtual.plugins.cache.CombinedVFSCache.findContext(CombinedVFSCache.java:116)

               at org.jboss.virtual.plugins.registry.DefaultVFSRegistry.getFile(DefaultVFSRegistry.java:148)

               at org.jboss.virtual.VFS.getRoot(VFS.java:243)

               at org.jboss.virtual.VFS.getRoot(VFS.java:313)

               at org.jboss.virtual.plugins.vfs.VirtualFileURLConnection.resolveVirtualFile(VirtualFileURLConnection.java:105)

               at org.jboss.virtual.plugins.vfs.VirtualFileURLConnection.getVirtualFile(VirtualFileURLConnection.java:118)

               at org.jboss.virtual.plugins.vfs.VirtualFileURLConnection.getInputStream(VirtualFileURLConnection.java:93)

               at java.net.URL.openStream(URL.java:1010)

               at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1195)

               at java.lang.Class.getResourceAsStream(Class.java:2030)

               at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:152)

               at org.springframework.mail.javamail.ConfigurableMimeFileTypeMap.createFileTypeMap(ConfigurableMimeFileTypeMap.java:144)

               at org.springframework.mail.javamail.ConfigurableMimeFileTypeMap.getFileTypeMap(ConfigurableMimeFileTypeMap.java:118)

               at org.springframework.mail.javamail.ConfigurableMimeFileTypeMap.afterPropertiesSet(ConfigurableMimeFileTypeMap.java:105)

               at org.springframework.mail.javamail.JavaMailSenderImpl.<init>(JavaMailSenderImpl.java:106)