Open swirlds-automation opened 1 year ago
Note that if per instance ThreadLocal
is somehow deemed justified, then calling ThreadLocal.remove()
in those instances is also required to avoid memory leaks in long living threads. Basically, this is an argument for redesign of the mechanisms relying on non-static ThreadLocals
rather than fixing them.
author:OlegMazurov, createdAt:2021-10-18T18:01:12Z, updatedAt=2021-10-18T18:01:12Z
See also #5185 author:OlegMazurov, createdAt:2021-10-20T17:59:51Z, updatedAt=2021-10-20T17:59:51Z
There are a few ThreadLocals in JasperDB / MerkleDb and VirtualMap, but all of them are static now. The only class from the list above that still uses non-static thread locals is CachingOperationProvider:
private final ThreadLocal<HashMap<AlgType, Alg>> context = ThreadLocal.withInitial(HashMap::new);
author:artemananiev, createdAt:2023-02-22T00:13:12Z, updatedAt=2023-02-22T00:13:12Z
migrated from:
url=https://github.com/swirlds/swirlds-platform/issues/4046
author:OlegMazurov, #:4046, createdAt:2021-10-15T22:51:32Z, updatedAt=2023-02-22T00:13:29Z
labels=Bug
DataFileReader.ThreadLocalSeekableByteChannel
extendsThreadLocal
. A non-staticseekableByteChannel
of that type is instantiated for eachDataFileReader
, thus a newThreadLocal
is repeatedly created ("key", not value).ThreadLocals
should be static.In other places: