Skip to content

Commit 9eeac8d

Browse files
committed
IGNITE-26608 Removed ThreadLocal access when closing scope.
1 parent 4d2f4d3 commit 9eeac8d

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

  • modules/commons/src/main/java/org/apache/ignite/internal/thread/context

modules/commons/src/main/java/org/apache/ignite/internal/thread/context/Context.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ private Context() {
7171
* @param attr Context Attribute.
7272
* @return Scope instance that, when closed, undoes the applied update. It is crucial to undo all applied Context
7373
* updates to free up thread-bound resources and avoid memory leaks, so it is highly encouraged to use a
74-
* try-with-resource block to close the returned Scope. Note, updates must be undone in the same order they were applied.
74+
* try-with-resource block to close the returned Scope. Note, updates must be undone in the same order and in the
75+
* same thread they were applied.
7576
*/
7677
public static <T> Scope set(ContextAttribute<T> attr, T val) {
7778
Context ctx = INSTANCE.get();
@@ -88,7 +89,8 @@ public static <T> Scope set(ContextAttribute<T> attr, T val) {
8889
* @param val2 Values associated with second Context Attribute.
8990
* @return Scope instance that, when closed, undoes the applied update. It is crucial to undo all applied Context
9091
* updates to free up thread-bound resources and avoid memory leaks, so it is highly encouraged to use a
91-
* try-with-resource block to close the returned Scope. Note, updates must be undone in the same order they were applied.
92+
* try-with-resource block to close the returned Scope. Note, updates must be undone in the same order and in the
93+
* same thread they were applied.
9294
*/
9395
public static <T1, T2> Scope set(
9496
ContextAttribute<T1> attr1, T1 val1,
@@ -108,7 +110,8 @@ public static <T1, T2> Scope set(
108110
* @param val3 Values associated with third Context Attribute.
109111
* @return Scope instance that, when closed, undoes the applied update. It is crucial to undo all applied Context
110112
* updates to free up thread-bound resources and avoid memory leaks, so it is highly encouraged to use a
111-
* try-with-resource block to close the returned Scope. Note, updates must be undone in the same order they were applied.
113+
* try-with-resource block to close the returned Scope. Note, updates must be undone in the same order and in the
114+
* same thread they were applied.
112115
*/
113116
public static <T1, T2, T3> Scope set(
114117
ContextAttribute<T1> attr1, T1 val1,
@@ -134,7 +137,8 @@ public static ContextSnapshot createSnapshot() {
134137
* @param snp Context Snapshot.
135138
* @return Scope instance that, when closed, undoes the applied operation. It is crucial to undo all applied Context
136139
* updates to free up thread-bound resources and avoid memory leaks, so it is highly encouraged to use a
137-
* try-with-resource block to close the returned Scope. Note, updates must be undone in the same order they were applied.
140+
* try-with-resource block to close the returned Scope. Note, updates must be undone in the same order and in the
141+
* same thread they were applied.
138142
*/
139143
public static Scope restoreSnapshot(ContextSnapshot snp) {
140144
return INSTANCE.get().restoreSnapshotInternal(snp);
@@ -198,7 +202,7 @@ private Scope restoreSnapshotInternal(ContextSnapshot newSnp) {
198202

199203
changeState(prevSnp, newSnp);
200204

201-
return () -> INSTANCE.get().changeState(newSnp, prevSnp);
205+
return () -> changeState(newSnp, prevSnp);
202206
}
203207

204208
/** */
@@ -209,7 +213,7 @@ private void changeState(ContextSnapshot expState, ContextSnapshot newState) {
209213
}
210214

211215
/** Represents Update applied to the Context. */
212-
private static class Update implements Scope, ContextSnapshot {
216+
private class Update implements Scope, ContextSnapshot {
213217
/** Updated attributes and their corresponding values. */
214218
private final AttributeValueHolder<?>[] attrVals;
215219

@@ -267,7 +271,7 @@ boolean holdsValueFor(ContextAttribute<?> attr) {
267271
}
268272

269273
/** */
270-
private static int mergeUpdatedAttributeBits(AttributeValueHolder<?>[] attrVals) {
274+
private int mergeUpdatedAttributeBits(AttributeValueHolder<?>[] attrVals) {
271275
int res = 0;
272276

273277
for (AttributeValueHolder<?> attrVal : attrVals)
@@ -278,7 +282,7 @@ private static int mergeUpdatedAttributeBits(AttributeValueHolder<?>[] attrVals)
278282

279283
/** */
280284
@Override public void close() {
281-
INSTANCE.get().undo(this);
285+
undo(this);
282286
}
283287
}
284288

0 commit comments

Comments
 (0)