mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-20 02:56:44 +00:00
Avoid thread safety issues with objectIds #162
This commit is contained in:
parent
b65c57ceba
commit
df9c466827
@ -16,6 +16,7 @@ import org.bson.Document;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
public class GameUniverse {
|
public class GameUniverse {
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ public class GameUniverse {
|
|||||||
|
|
||||||
private long time;
|
private long time;
|
||||||
|
|
||||||
private long nextObjectId = 0;
|
private AtomicLong nextObjectId = new AtomicLong(0);
|
||||||
|
|
||||||
private int maxWidth = 0xFFFF;
|
private int maxWidth = 0xFFFF;
|
||||||
|
|
||||||
@ -251,7 +252,7 @@ public class GameUniverse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long getNextObjectId() {
|
public long getNextObjectId() {
|
||||||
return ++nextObjectId;
|
return nextObjectId.getAndIncrement();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGuestUsername() {
|
public String getGuestUsername() {
|
||||||
@ -287,6 +288,6 @@ public class GameUniverse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setNextObjectId(long nextObjectId) {
|
public void setNextObjectId(long nextObjectId) {
|
||||||
this.nextObjectId = nextObjectId;
|
this.nextObjectId.set(nextObjectId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user