[concurrency-interest] RRWL with 'bad' Thread.getId() implementations

Doug Lea dl at cs.oswego.edu
Wed Jun 26 06:43:54 EDT 2013


On 06/25/13 19:03, Doug Lea wrote:
>

> We can and probably should fix this immediately by grabbing
> the Thread's "tid" field instead of calling getId.

I committed this change to jsr166 sources, so it should eventually
make its way into OpenJDK.


> On the form of the added method:
> By analogy to Object.hashCode() (orverridable) vs
> System.identityHashCode(Object) (not). maybe the
> best place for this method is System.getThreadId(Thread)?

Or less disruptively, it might as well be in class Thread, but
with spec wording adapted from System.identityHashCode:

     /**
      * Returns the identifier for the given Thread, as would
      * be returned by the default {@link #getId} method,
      * whether or not the thread's class overrides {@code getId()}.
      *
      * @param thread the thread
      * @return the id
      */
     public static final long getThreadId(Thread thread) {
         return thread.tid;
     }





More information about the Concurrency-interest mailing list