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

Michael Wechner michael.wechner at wyona.com
Mon Nov 22 22:16:20 CET 2010


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