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/OverloadedWorldHolder.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/OverloadedWorldHolder.java')
-rw-r--r-- | EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java index 84561b6e5..ef9f605ed 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/OverloadedWorldHolder.java @@ -6,6 +6,7 @@ package org.anjocaido.groupmanager.dataholder; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.anjocaido.groupmanager.data.User; @@ -19,7 +20,7 @@ public class OverloadedWorldHolder extends WorldDataHolder { /** * */ - protected Map<String, User> overloadedUsers = new HashMap<String, User>(); + protected final Map<String, User> overloadedUsers = Collections.synchronizedMap(new HashMap<String, User>()); /** * @@ -112,9 +113,11 @@ public class OverloadedWorldHolder extends WorldDataHolder { if (groupName.equals(getDefaultGroup())) { return false; } + synchronized(getGroups()) { for (String key : getGroups().keySet()) { if (groupName.equalsIgnoreCase(key)) { getGroups().remove(key); + synchronized(getUsers()) { for (String userKey : getUsers().keySet()) { User user = getUsers().get(userKey); if (user.getGroupName().equalsIgnoreCase(key)) { @@ -122,7 +125,9 @@ public class OverloadedWorldHolder extends WorldDataHolder { } } + } //OVERLOADED CODE + synchronized(overloadedUsers) { for (String userKey : overloadedUsers.keySet()) { User user = overloadedUsers.get(userKey); if (user.getGroupName().equalsIgnoreCase(key)) { @@ -130,11 +135,13 @@ public class OverloadedWorldHolder extends WorldDataHolder { } } + } //END OVERLOAD setGroupsChanged(true); return true; } } + } return false; } @@ -146,6 +153,7 @@ public class OverloadedWorldHolder extends WorldDataHolder { public Collection<User> getUserList() { Collection<User> overloadedList = new ArrayList<User>(); + synchronized(getUsers()) { Collection<User> normalList = getUsers().values(); for (User u : normalList) { if (overloadedUsers.containsKey(u.getName().toLowerCase())) { @@ -154,6 +162,7 @@ public class OverloadedWorldHolder extends WorldDataHolder { overloadedList.add(u); } } + } return overloadedList; } |