小编Mur*_*ali的帖子

如何解决findbug对java.util.concurrent.ConcurrentHashMap的调用序列可能不是原子的

嗨我得到的错误"调用java.util.concurrent.ConcurrentHashMap的序列可能不是原子的"当我在我的项目中运行find bug时,代码如下.

public static final ConcurrentHashMap<String,Vector<Person>> personTypeMap = new ConcurrentHashMap<String, Vector<Person>>();

    private static void setDefaultPersonGroup() {


        PersonDao crud = PersonDao.getInstance();
        List<Person> personDBList = crud.retrieveAll();
        for (Person person : personDBList) {
            Vector<Person> personTypeCollection = personTypeMap.get(person
                    .getGroupId());
            if (personTypeCollection == null) {
                personTypeCollection = new Vector<Person>();
                personTypeMap.put(personTypeCollection.getGroupId(),
                        personTypeCollection);
            }
            personTypeCollection.add(person);
        }
    }
Run Code Online (Sandbox Code Playgroud)

我在线下的personTypeMap.put(personTypeCollection.getGroupId(),personTypeCollection)面临问题;

任何人都可以帮我解决问题.

java findbugs concurrenthashmap java.util.concurrent

9
推荐指数
1
解决办法
4218
查看次数

Collections.synchronizedList vs Vector

我想使用集合类来添加,删除和检索多个线程中的对象.

Collections.synchronizedList并且Vector这两个类都是线程安全的.有哪位告诉我之间的区别Collections.synchronizedList,并Vector解释说,我什么时候应该使用与VectorCollections.synchronizedList

java collections multithreading thread-safety

7
推荐指数
1
解决办法
8118
查看次数

哪个Java集合类更适合在多线程环境中使用

嗨,我是Java多线程环境的新手.我必须在一个线程中添加,更新和删除集合中的对象集.同时我将检查并在另一个线程上迭代该对象.

列表和设置不是线程安全的.任何人都可以分享一下,哪个集合/ Map类更适合在多线程环境中使用?

java collections concurrency multithreading java.util.concurrent

0
推荐指数
1
解决办法
6356
查看次数