Skip to content

Commit c847e5f

Browse files
committed
Cache the ThreadId - as this is called many times and is a large source of garbage.
1 parent 369f45f commit c847e5f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

affinity/src/main/java/net/openhft/affinity/impl/WindowsJNAAffinity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public enum WindowsJNAAffinity implements IAffinity {
4141
INSTANCE;
4242
public static final boolean LOADED;
4343
private static final Logger LOGGER = LoggerFactory.getLogger(WindowsJNAAffinity.class);
44+
private final ThreadLocal<Integer> THREAD_ID = new ThreadLocal<>();
4445

4546
@Override
4647
public long getAffinity() {
@@ -99,7 +100,10 @@ public int getProcessId() {
99100

100101
@Override
101102
public int getThreadId() {
102-
return Kernel32.INSTANCE.GetCurrentThreadId();
103+
Integer tid = THREAD_ID.get();
104+
if (tid == null)
105+
THREAD_ID.set(tid = Kernel32.INSTANCE.GetCurrentThreadId());
106+
return tid;
103107
}
104108

105109

0 commit comments

Comments
 (0)