File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed
worldedit-core/src/main/java/com/sk89q/worldedit/session/request Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change 3131import java .util .concurrent .ConcurrentHashMap ;
3232
3333/**
34- * Describes the current request using a {@link ThreadLocal }.
34+ * Describes the current request using a {@link ConcurrentHashMap }.
3535 */
3636public final class Request {
3737
38- private static final ThreadLocal <Request > threadLocal = ThreadLocal .withInitial (Request ::new );
39- //FAWE start
40- // TODO any better way to deal with this?
38+ //FAWE start use CHM instead of ThreadLocal
4139 private static final Map <Thread , Request > requests = new ConcurrentHashMap <>();
4240 //FAWE end
4341
@@ -56,9 +54,6 @@ public final class Request {
5654 //FAWE end
5755
5856 private Request () {
59- //FAWE start
60- requests .put (Thread .currentThread (), this );
61- //FAWE end
6257 }
6358
6459 //FAWE start
@@ -162,17 +157,18 @@ public void setEditSession(@Nullable EditSession editSession) {
162157 * @return the current request
163158 */
164159 public static Request request () {
165- return threadLocal . get ( );
160+ return requests . computeIfAbsent ( Thread . currentThread (), t -> new Request () );
166161 }
167162
168163 /**
169164 * Reset the current request and clear all fields.
170165 */
171166 public static void reset () {
172- request ().invalidate ();
173- threadLocal .remove ();
174167 //FAWE start
175- requests .remove (Thread .currentThread ());
168+ Request request = requests .remove (Thread .currentThread ());
169+ if (request != null ) {
170+ request .invalidate ();
171+ }
176172 //FAWE end
177173 }
178174
You can’t perform that action at this time.
0 commit comments