Seam job scheduling and @Asynchronous
jgreene Oct 9, 2008 3:45 PMHello-
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:
|@Create public void initializeStartup() { accountDeactivationHandler.checkAccounts(120000); }|
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:
|@Asynchronous 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.