[jbossts-issues] [JBoss JIRA] (JBTM-2949) Remove synchronization from ThreadUtil.getThreadId

Luis Barreiro (JIRA) issues at jboss.org
Fri Oct 20 12:25:00 EDT 2017


    [ https://issues.jboss.org/browse/JBTM-2949?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13480069#comment-13480069 ] 

Luis Barreiro commented on JBTM-2949:
-------------------------------------

Looking at OpenJ9 code, it uses a counter as well. In the event that there is a JVM that does it differently, it won't be an issue unless IDs are reused fairly aggressively, which seems unlikely.

The problem with option 1 is complexity, having to maintain a non-standard {{Map}}. Also, conceptually, assigning IDs to objects that already have one seems just wrong.

> Remove synchronization from ThreadUtil.getThreadId
> --------------------------------------------------
>
>                 Key: JBTM-2949
>                 URL: https://issues.jboss.org/browse/JBTM-2949
>             Project: JBoss Transaction Manager
>          Issue Type: Enhancement
>            Reporter: Luis Barreiro
>
> JBTM-2808 adds synchronization on {{ThreadUtil.getThreadId()}} but that solution does not scale well enough under high contention. 
> There seems to be ways to remove this synchronization:
> # *ConcurrentWeakHashMap* - replace the current {{WeakHashMap}} for a similar data structure that can handle concurrent access. This keeps the same behavior.
> # *Use Thread.getId()* - remove all mappings and generate the {{threadId}} from the {{Thread}}. Although the javadoc mentions that IDs can be reused, the implementation is a counter, like what {{ThreadUtil}} has now. This is the simplest and most elegant fix.
> # *Remove {{threadId}}* - remove the generation of {{threadId}} and use the {{Thread}} throughout the code, generating string IDs when necessary. Probably yields the best performance, but requires the most changes.



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the jbossts-issues mailing list