Announcement Announcement Module
Collapse
No announcement yet.
mongodb write throw ConcurrentModificationException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • mongodb write throw ConcurrentModificationException

    I just use 10 threads to write data ,mongotemplate throw a exception:
    spring-data-mongodb version is 1.0.0.M3

    Code:
    Exception in thread "Thread-35" java.util.ConcurrentModificationException
    	at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
    	at java.util.HashMap$ValueIterator.next(HashMap.java:822)
    	at org.springframework.data.mapping.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:110)
    	at org.springframework.data.document.mongodb.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:362)
    	at org.springframework.data.document.mongodb.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:317)
    	at org.springframework.data.document.mongodb.convert.MappingMongoConverter.write(MappingMongoConverter.java:287)
    	at org.springframework.data.document.mongodb.MongoTemplate.doInsert(MongoTemplate.java:691)
    	at org.springframework.data.document.mongodb.MongoTemplate.insert(MongoTemplate.java:648)
    	at org.springframework.data.document.mongodb.MongoTemplate.insert(MongoTemplate.java:636)
    	at com.skymobi.sns.feed.ActivityMessageListener.writePublicBox(ActivityMessageListener.java:132)
    Data model like :

    Code:
    @Document
    public class PublicBox {
    	@Id
    	private ObjectId id;
        private String activityId;
    
        private Date postedTime;

    Test code :

    Code:
     ApplicationContext context = new AnnotationConfigApplicationContext(WriterAppConfig.class);
    
            final MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class);
    
            for (int i = 0; i < 50; i++) {
                Thread thread = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        PublicBox publicBox = new PublicBox();
                        publicBox.setId(ObjectId.get());
                        publicBox.setActivityId("test");
                        publicBox.setPostedTime(new Date());
                        mongoTemplate.insert(publicBox);
                        System.out.println("sdsdsd");
                    }
                });
                thread.start();
            }
    Help me!
    Last edited by yishh; Aug 9th, 2011, 11:26 PM. Reason: update code

  • #2
    It seems you create a race condition while building mapping metadata. I've created DATACMNS-65 [0] to keep track of it. Meanwhile you should be able to workaround this by setting initialEntitySet on MongoMappingContext. This will cause the metadata be created before any interaction with the mapping context.

    Comment


    • #3
      Should be fixed in the snapshor repository.

      Comment

      Working...
      X