1 Reply Latest reply on Oct 9, 2008 6:03 PM by Joe Greene

    Seam job scheduling and @Asynchronous

    Joe Greene Novice


      I've seen and read the posts that discuss creating a Seam job scheduler at startup, and have applied this advice.  I've created a startup manager bean annotated with @Startup, and this bean has a method annotated with @Create.  Inside this method, I call the method I want to run asynchronously at a periodic interval.  Here is the method in the startup bean marked with @Create:

      public void initializeStartup()

      The 'accountDeactivationHandler' is an application-scoped Seam POJO that has the 'checkAccounts' method.  Here is that method's signature:

      |public void checkAccounts(@IntervalDuration Long interval)

      I want the 'checkAccounts' method to execute on startup and, for testing purposes, every 2 minutes after that.  On startup, the 'checkAccounts' method indeed executes, but does not execute after that.  I expect that since I do not have @Asynchronous applied yet.  So I then applied this annotation to the 'checkAccounts' method like this:

      public void checkAccounts(@IntervalDuration Long interval)|

      When I do this, I get the following error (I'm using OC4J):

      Caused by: javax.naming.NamingException: Not in an application scope - start OC4J with the -userThreads switch if using user-created threads
           at com.evermind.server.PreemptiveApplicationContext.getContext(PreemptiveApplicationContext.java:30)
           at com.evermind.naming.FilterContext.lookup(FilterContext.java:126)
           at com.evermind.server.PreemptiveApplicationContext.lookup(PreemptiveApplicationContext.java:42)
           at javax.naming.InitialContext.lookup(InitialContext.java:351)
           at org.jboss.seam.transaction.Transaction.getUserTransaction(Transaction.java:79)
           at org.jboss.seam.transaction.Transaction.createUTTransaction(Transaction.java:71)
           at org.jboss.seam.transaction.Transaction.getTransaction(Transaction.java:44)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:585)
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
           at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:125)
           ... 32 more

      Is it not possible to create an asynchronous scheduled task to run at a periodic interval using only a Seam POJO?  Do I need to force this to run in the EJB container by making it a stateless session bean for instance?

      Any help would be greatly appreciated.  Thank you.

        • 1. Re: Seam job scheduling and @Asynchronous
          Joe Greene Novice

          I have converted my POJO arrangement into a stateless EJB with a local interface.  I use the @Asynchronous annotation on the method in the interface, and removed it from the method in the implementation class.  When I start up now, the method marked with @Create runs, but the method using @IntervalDuration as a parameter does not run at all.  Instead, I get the following error:

          ERROR [Contexts] could not discover transaction status

          Has anyone created a recurring task in Seam using @IntervalDuration like I'm trying to do, either strictly as a POJO, or as a stateless EJB like I describe here?

          I would really appreciate any help.  We are currently using OC4J application server with Seam 2.0.1GA.  Thank you.