ignite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maxim Muzafarov <maxmu...@gmail.com>
Subject Class field ThreadLocal. Why not static?
Date Mon, 10 Sep 2018 08:54:05 GMT
Igniters,

According to javadoc [1] class ThreadLocal:
`ThreadLocal instances are typically private *static* fields in classes
that wish to associate state with a thread (e.g., a user ID or Transaction
ID).`

So, AFAIK non-static ThreadLocal usage means as `per thread - per class
instance`. What the real cases of using non-static ThreadLocal class fields
in Ignite code project? When we need it?

In Ignite code project I've found ThreadLocal usage as:
 - non-static - 67
 - static  - 68

Back to my example, I've checked FileWriteAheadLogManager. It has:
1) private final ThreadLocal<Boolean> interrupted [2]
2) private final ThreadLocal<WALPointer> lastWALPtr [3]
I think both of these fields should be set and used as `static`. Can anyone
confirm it?


[1] https://docs.oracle.com/javase/8/docs/api/java/lang/ThreadLocal.html
[2]
https://github.com/apache/ignite/blob/master/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java#L253
[3]
https://github.com/apache/ignite/blob/master/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/FileWriteAheadLogManager.java#L340
-- 
--
Maxim Muzafarov

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message