considering the circumstances i was forced to find another solution for automatic calling EJB method. Unfortunately this was, for my opinion, less elegant and more limited solution.
I'll write short tutorial for how set WebSphere scheduler for all of you who got need to use it.
So here it is, using EJB 3.0 and WebSphere 7
1) Set scheduler in WebSphere console (you'll need database connection set as well, because scheduler automaticly creates few tables for managing tasks)
Go to resources -> schedulers -> new
Set JNDI name by which you'll call Scheduler from your application (in this example, it will be sched/testScheduler), and ofcourse choose database conneciton.
Poll interval - i'm not sure what is purpose of it because i set interval for tasks in application, but anyway i set it to 30min.
Table prefix - i guess choose whatever you prefer
Now after you created new Scheduler, select it in table (resources -> schedulers) and click 'Create tables'.
2) EJB part - i created stateless session bean and implemented com.ibm.websphere.scheduler.TaskHandler with all it's methods. Then i removed @Override annotations from implemented methods, and removed "implements com.ibm.websphere.scheduler.TaskHandler" part of code.
Ofcourse, now i had to tell in ejb-jar.xml that my bean will implement com.ibm.websphere.scheduler.TaskHandler (as remote) and com.ibm.websphere.scheduler.TaskHandlerHome (as remote home):
Finally, here is code for setting and canceling tasks for particular scheduler (i call it in contextListener when application starts/stops)
So as you can see, taskInfo.setTaskHandler(home) is telling what bean will execute every time task is called.
I'm trying to walk through this for an application I'm working on right now. Neither myself nor my team mates have a ton of experience with an EJB project, so excuse my ignorance if this is a basic question.
How do I set up a context listener for application startup?
I've set up my bean and my task, but have no idea how to set up a listener, and can't find anything on the web. Thanks.
Joined: Apr 01, 2011
Me neither have a lot of experience but i'll do my best to explain.
Context listener is in Web part of application, so in my web.xml file i register it (controller is a name of package, ContextListener is name of a class):
Also, your class must implement javax.servlet.ServletContextListener interface. ServletContextListener has two methods, one when application start and other when applicaiton stops:
Joined: Apr 01, 2011
I forgot to mention - i think you should stop task that you are about to create when application start because if applicition don't stop "normaly" task will "live on" so when you start application you will have 2 tasks actualy.