[concurrency-interest] Ensure Callable.call is invoked fromconstructing thread?
tackline at tackline.plus.com
Fri Jun 9 12:31:54 EDT 2006
Kris Schneider wrote:
> I need to ensure that a Callable is called from the same thread within
> which it was constructed:
> The two approaches that immediately came to mind were to use a reference
> object or System.identityHashCode(Thread.currentThread()). Any thoughts on
> which might be better or if there are other approaches that are better
> still? Thanks.
System.identityHashCode does not produce unique values. A very common
mistake - the documentation is a bit poor.
I guess Thread.currentThread().getId() should work (since 1.5), as
should new WeakReference<Thread>(Thread.currentThread()).
More information about the Concurrency-interest