[Yanel-dev] Running background jobs in the background using threads

Michael Wechner michael.wechner at wyona.com
Wed Nov 24 14:39:13 CET 2010


Hi

I have started to improve this by using a "persistent" repository 
instead the session which might expire, whereas
see the methods

attachThreadIDToRepository()
getThreadFromRepository()
detachThreadIDFromRepository()

whereas it's not completely finished yet, but seems to work fine so far.
The main problem is to get back the actual thread instance. Also see

http://nadeausoftware.com/articles/2008/04/java_tip_how_list_and_find_threads_and_thread_groups#GettingathreadbyID

I assume this was one reason to attach the thread reference to the 
session, because
this way one can easily access the thread instance as long as the 
session exists.

Well, will keep you posted.

Cheers

Michael


src/impl/java/org/wyona/yanel/impl/resources/usecase/thread/UsecaseThread.java

On 11/22/10 10:16 PM, Michael Wechner wrote:
> Hi
>
> Quite often one has to process something which can take more time than 
> which is expected from
> a regular request. Hence it's nice if one can start threads running in 
> the background and Yanel
> already sends a response with a note saying "hey, we are working on it 
> ... please stay tuned ...".
>
> Yanel does offer such a component which simplifies such threads:
>
> src/impl/java/org/wyona/yanel/impl/resources/usecase/thread/ThreadUsecaseResource.java 
>
>
> and in order to stay tuned the thread ID is attached to the HTTP 
> session. But the problem with this
> approach is that the session might expire before the job is finished, 
> hence I have added a note to
>
> Index: 
> src/impl/java/org/wyona/yanel/impl/resources/usecase/thread/ThreadUsecaseResource.java
> ===================================================================
> --- 
> src/impl/java/org/wyona/yanel/impl/resources/usecase/thread/ThreadUsecaseResource.java   
>  (revision 54828)
> +++ 
> src/impl/java/org/wyona/yanel/impl/resources/usecase/thread/ThreadUsecaseResource.java   
>  (working copy)
> @@ -123,6 +123,7 @@
>       * @return thread or null if the thread is not attached to the 
> session.
>       */
>      public UsecaseThread getThread() {
> +        // TODO: Is it really a good idea to set/get the thread ID 
> within the session, because what if the session expires?!
>          HttpSession session = 
> getEnvironment().getRequest().getSession();
>          return UsecaseThread.getThreadFromSession(session, 
> getThreadID());
>      }
>
> I think it probably would be safer to attach it to the user profile 
> which has started it (in case it has been started
> by a user).
>
> WDYT?
>
> Cheers
>
> Michael



More information about the Yanel-development mailing list