Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Calling EJB Bean with WebSphere application server Scheduler

 
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

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.

Before:



After:



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.

Method to cancel all tasks with same name:





 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
nikola petanjak
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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:

 
nikola petanjak
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've created a tutorial that explains how to do this:
https://github.com/aviramsegal/articles/blob/master/WebSphereScheduler/WebSphereScheduler.md
 
Right! We're on it! Let's get to work tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic