1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.util.concurrent;
17
18 import io.netty.util.internal.InternalThreadLocalMap;
19 import io.netty.util.internal.UnstableApi;
20 import io.netty.util.internal.logging.InternalLogger;
21 import io.netty.util.internal.logging.InternalLoggerFactory;
22
23
24
25
26 public class FastThreadLocalThread extends Thread {
27
28 private static final InternalLogger logger = InternalLoggerFactory.getInstance(FastThreadLocalThread.class);
29
30
31 private final boolean cleanupFastThreadLocals;
32
33 private InternalThreadLocalMap threadLocalMap;
34
35 public FastThreadLocalThread() {
36 cleanupFastThreadLocals = false;
37 }
38
39 public FastThreadLocalThread(Runnable target) {
40 super(FastThreadLocalRunnable.wrap(target));
41 cleanupFastThreadLocals = true;
42 }
43
44 public FastThreadLocalThread(ThreadGroup group, Runnable target) {
45 super(group, FastThreadLocalRunnable.wrap(target));
46 cleanupFastThreadLocals = true;
47 }
48
49 public FastThreadLocalThread(String name) {
50 super(name);
51 cleanupFastThreadLocals = false;
52 }
53
54 public FastThreadLocalThread(ThreadGroup group, String name) {
55 super(group, name);
56 cleanupFastThreadLocals = false;
57 }
58
59 public FastThreadLocalThread(Runnable target, String name) {
60 super(FastThreadLocalRunnable.wrap(target), name);
61 cleanupFastThreadLocals = true;
62 }
63
64 public FastThreadLocalThread(ThreadGroup group, Runnable target, String name) {
65 super(group, FastThreadLocalRunnable.wrap(target), name);
66 cleanupFastThreadLocals = true;
67 }
68
69 public FastThreadLocalThread(ThreadGroup group, Runnable target, String name, long stackSize) {
70 super(group, FastThreadLocalRunnable.wrap(target), name, stackSize);
71 cleanupFastThreadLocals = true;
72 }
73
74
75
76
77
78 public final InternalThreadLocalMap threadLocalMap() {
79 if (this != Thread.currentThread() && logger.isWarnEnabled()) {
80 logger.warn(new RuntimeException("It's not thread-safe to get 'threadLocalMap' " +
81 "which doesn't belong to the caller thread"));
82 }
83 return threadLocalMap;
84 }
85
86
87
88
89
90 public final void setThreadLocalMap(InternalThreadLocalMap threadLocalMap) {
91 if (this != Thread.currentThread() && logger.isWarnEnabled()) {
92 logger.warn(new RuntimeException("It's not thread-safe to set 'threadLocalMap' " +
93 "which doesn't belong to the caller thread"));
94 }
95 this.threadLocalMap = threadLocalMap;
96 }
97
98
99
100
101 @UnstableApi
102 public boolean willCleanupFastThreadLocals() {
103 return cleanupFastThreadLocals;
104 }
105
106
107
108
109 @UnstableApi
110 public static boolean willCleanupFastThreadLocals(Thread thread) {
111 return thread instanceof FastThreadLocalThread &&
112 ((FastThreadLocalThread) thread).willCleanupFastThreadLocals();
113 }
114
115
116
117
118
119
120
121
122
123
124
125 public boolean permitBlockingCalls() {
126 return false;
127 }
128 }