Using ThreadLocal storage
This commit is contained in:
parent
755a0ad7ab
commit
4e008ab208
1 changed files with 2 additions and 7 deletions
|
@ -2,14 +2,9 @@ package ru.betterend.util;
|
||||||
|
|
||||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||||
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class GlobalState {
|
public class GlobalState {
|
||||||
private static final ConcurrentHashMap<Thread, GlobalState> statePool = new ConcurrentHashMap<>();
|
private static final ThreadLocal<GlobalState> STATE = ThreadLocal.withInitial(()->new GlobalState());
|
||||||
public static void clearStatePool(){
|
public static GlobalState stateForThread() { return STATE.get(); }
|
||||||
statePool.clear();
|
|
||||||
}
|
|
||||||
public static GlobalState stateForThread() { return statePool.computeIfAbsent(Thread.currentThread(), t-> new GlobalState()); }
|
|
||||||
|
|
||||||
public final MutableBlockPos POS = new MutableBlockPos();
|
public final MutableBlockPos POS = new MutableBlockPos();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue