diff options
author | snowleo <schneeleo@gmail.com> | 2012-09-10 20:49:07 +0200 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2012-09-10 20:49:07 +0200 |
commit | 1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc (patch) | |
tree | 5c494cf4d05d847fd7811dfa06bada20f4d75719 /EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java | |
parent | 736a6d273abb000c81b17d0142ce358d2225f873 (diff) | |
download | Essentials-1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc.tar Essentials-1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc.tar.gz Essentials-1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc.tar.lz Essentials-1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc.tar.xz Essentials-1cf0ebbd7f120c0b8d421cc459f2d5a1386d82dc.zip |
Thread safety for GM
Diffstat (limited to 'EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java')
-rw-r--r-- | EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java index 665fe227d..8a3c4c102 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/UsersDataHolder.java @@ -1,6 +1,7 @@ package org.anjocaido.groupmanager.dataholder;
import java.io.File;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -22,7 +23,7 @@ public class UsersDataHolder { /**
* The actual groups holder
*/
- private Map<String, User> users = new HashMap<String, User>();
+ private final Map<String, User> users = Collections.synchronizedMap(new HashMap<String, User>());
/**
* Constructor
@@ -35,12 +36,14 @@ public class UsersDataHolder { this.dataSource = dataSource;
//push this data source to the users, so they pull the correct groups data.
+ synchronized(users) {
for (User user : users.values())
user.setDataSource(this.dataSource);
-
+ }
}
/**
+ * Note: Iteration over this object has to be synchronized!
* @return the users
*/
public Map<String, User> getUsers() {
@@ -51,9 +54,8 @@ public class UsersDataHolder { /**
* @param users the users to set
*/
- public void setUsers(Map<String, User> users) {
-
- this.users = users;
+ public void resetUsers() {
+ this.users.clear();
}
/**
|