On Wed, Jun 25, 2008 at 4:26 AM, Jerome Louvel <[EMAIL PROTECTED]> wrote:

> In order to ensure that the methods still work when invoked by another
> thread, the engine could keep a copy of those thread local variables are
> restore them on the new thread when calling again the Restlet code.
>
> For example, there is a getThread(Runnable) method that has been added to
> Context class that already does this for manually created threads:
>
> http://www.restlet.org/documentation/snapshot/api/org/restlet/Context.html#getThread(java.lang.Runnable)
>

This approach forces you to manage threads explicitly and thus won't work
with, for example, the Executor framework. Encouraging direct manipulation
of threads is a Bad Thing, so I think it's important either to reduce the
dependency on thread-locals or to provide a way to pass important
thread-locals through the Executor framework.

One way to do the latter would be to create an ExecutorService decorator
that wraps each submitted task with code to set the thread-locals before the
task executes and to clear them when it's done executing.

--tim

Reply via email to