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 java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class GlobalState {
|
||||
private static final ConcurrentHashMap<Thread, GlobalState> statePool = new ConcurrentHashMap<>();
|
||||
public static void clearStatePool(){
|
||||
statePool.clear();
|
||||
}
|
||||
public static GlobalState stateForThread() { return statePool.computeIfAbsent(Thread.currentThread(), t-> new GlobalState()); }
|
||||
private static final ThreadLocal<GlobalState> STATE = ThreadLocal.withInitial(()->new GlobalState());
|
||||
public static GlobalState stateForThread() { return STATE.get(); }
|
||||
|
||||
public final MutableBlockPos POS = new MutableBlockPos();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue