How to cancel or remove Persistent EJBTimers
Asked Answered
A

3

5

When we use persistent EJBTimer with @schedule and persistent=true, deploy it to cluster and then we change the actual schedule within @Schedule and re-deploy to the cluster, does the original schedule get replaced with the new one ( removed and added with new parameters ), or both the schedules remain active ( keeping in mind the persistent=true is set )

This is what I have read so far - Each scheduler instance has a unique jndi name and @schedule automatically creates a timer through application deployment so it would be better to remove the automatic created EJBTimer or cancel the original schedule to avoid trouble. But I don't know how to cancel the original schedule programmatically or would that need to be done by the websphere admins, if both the original and changed schedules remain active

Also from this document, the removeAutomaticEJBTimers command is used to remove timers from a specified scheduler, but that also seems in the area of a websphere admin, not a developer.

How can a developer programmatically cancel an automatic EJBTimer created by using @Schedule annotation?

I am using Java EE 6 with Websphere 8.5 and EJB 3.1.

Avitzur answered 11/2, 2015 at 17:59 Comment(3)
Automatic timers are removed during application uninstallation. Check these 2 posts EJB Timer when redepolyed.. and Remove EJB timer tasksPlunge
Thanks Gas. I had already looked at those links. But the Scheduled EJB doesn't seem to "go away". I am wondering if this is because - in our company - the applications are not "Uninstalled" and "re-installed", but they are "un-deployed" and "re-deployed". In terms of WAS, I do not know what is the difference between the two, but I am wondering if that is why the timers are not cancelled?Avitzur
Also, for using cancelEJBTimer, reading through the links, it seems it cancels ALL other timers too, so of course, our WAS admins are leary to use that approach. Hence I am still wondering, what can I as a developer do to cancel a timer created by @Schedule ?Avitzur
P
0

See this page Creating timers using the EJB timer service

The application server automatically removes persistent automatic timers from the database when you uninstall the application while the server is running. If the application server is not running, you must manually delete the automatic timers from the database. Additionally, if you add, remove, or change the metadata for automatic timers while the server is not running, you must manually delete the automatic timers.

I have the following class:

@Stateless
@LocalBean
public class HelloBean {
    @Schedule(persistent=true, minute="*", hour="*", info="myTimer")
    public void printHello() {
        System.out.println("### hello");
    }

}

When I install it to the server, I can find related automatic timer:

C:\IBM\WebSphere\AppServer85\profiles\AppSrv02\bin>findEJBTimers.bat server1 -all
ADMU0116I: Tool information is being logged in file C:\IBM\WebSphere\AppServer85\profiles\AppSrv02\logs\server1\EJBTimers.log
ADMU0128I: Starting tool with the AppSrv02 profile
ADMU3100I: Reading configuration for server: server1
EJB timer : 3     Expiration: 2/14/15 12:39 PM     Calendar
   EJB    : ScheduleTestEAR, ScheduleTest.jar, HelloBean
   Info   : myTimer
   Automatic timer with timout method: printHello
Calendar expression: [start=null, end=null, timezone=null, seconds="0",
           minutes="*", hours="*", dayOfMonth="*", month="*", dayOfWeek="*", year="*"]
1 EJB timer tasks found

After uninstalling application, the timer is removed:

C:\IBM\WebSphere\AppServer85\profiles\AppSrv02\bin>findEJBTimers.bat server1 -all
ADMU0116I: Tool information is being logged in file
           C:\IBM\WebSphere\AppServer85\profiles\AppSrv02\logs\server1\EJBTimers.log
ADMU0128I: Starting tool with the AppSrv02 profile
ADMU3100I: Reading configuration for server: server1
0 EJB timer tasks found

I don't know how you are 'redeploying' your applications, but looks like your process is incorrect. As in normal install/uninstall/update process automatic timers are correctly removed.

UPDATE
On the same page you have info regarding ND environment:

Automatic persistent timers are removed from their persistent store when their containing module or application is uninstalled. Therefore, do not update applications that use automatic persistent timers with the Rollout Update feature. Doing so uninstalls and reinstalls the application while the cluster is still operational, which might cause failure in the following cases:

  • If a timer running in another cluster member activates after the database entry is removed and before the database entry is recreated, then the timer fails. In this case, a com.ibm.websphere.scheduler.TaskPending exception is written to the First Failure Data Capture (FFDC), along with the SCHD0057W message, indicating that the task information in the database has been changed or canceled.

  • If the timer activates on a cluster member that has not been updated after the timer data in the database has been updated, then the timer might fail or cause other failures if the new timer information is not compatible with the old application code still running in the cluster member.

Plunge answered 14/2, 2015 at 11:52 Comment(3)
Thanks. I will ask the WAS admins to check this on the servers - I am sorry, but I don't really know what the difference between uninstall vs. undeply is, but our WAS admins keep insisting that they have been doing undeploy for years - since WAS 5, and to uninstall, we need to justify why that is needed, so I am trying to gather information - in the meantime, I will also try this on my local RAD - but I may not know how it behaves on ND, even if I can do it on my local set-up. One question - If I do ADD / Remove from RAD, is that considered uninstall or do I have to use admin consode.Avitzur
@Avitzur You may do it in RAD, Add/Remove is similar to uninstall. You have to gather more details from your admins, what they are doing, as there is no 'deploy`Plunge
Thanks Gas. I requested our websphere admins to cancel the existing EJBTimer for this application and then redeployed the application to our DEV ND environment. That seems to have stopped the continuous running of the timer.Avitzur
C
7

Do the following to remove persisted EJB timers:

Delete directory jboss-home\standalone\data\timer-service-data{yourporjectname}.{serivename}

Claussen answered 19/7, 2016 at 22:27 Comment(0)
P
0

See this page Creating timers using the EJB timer service

The application server automatically removes persistent automatic timers from the database when you uninstall the application while the server is running. If the application server is not running, you must manually delete the automatic timers from the database. Additionally, if you add, remove, or change the metadata for automatic timers while the server is not running, you must manually delete the automatic timers.

I have the following class:

@Stateless
@LocalBean
public class HelloBean {
    @Schedule(persistent=true, minute="*", hour="*", info="myTimer")
    public void printHello() {
        System.out.println("### hello");
    }

}

When I install it to the server, I can find related automatic timer:

C:\IBM\WebSphere\AppServer85\profiles\AppSrv02\bin>findEJBTimers.bat server1 -all
ADMU0116I: Tool information is being logged in file C:\IBM\WebSphere\AppServer85\profiles\AppSrv02\logs\server1\EJBTimers.log
ADMU0128I: Starting tool with the AppSrv02 profile
ADMU3100I: Reading configuration for server: server1
EJB timer : 3     Expiration: 2/14/15 12:39 PM     Calendar
   EJB    : ScheduleTestEAR, ScheduleTest.jar, HelloBean
   Info   : myTimer
   Automatic timer with timout method: printHello
Calendar expression: [start=null, end=null, timezone=null, seconds="0",
           minutes="*", hours="*", dayOfMonth="*", month="*", dayOfWeek="*", year="*"]
1 EJB timer tasks found

After uninstalling application, the timer is removed:

C:\IBM\WebSphere\AppServer85\profiles\AppSrv02\bin>findEJBTimers.bat server1 -all
ADMU0116I: Tool information is being logged in file
           C:\IBM\WebSphere\AppServer85\profiles\AppSrv02\logs\server1\EJBTimers.log
ADMU0128I: Starting tool with the AppSrv02 profile
ADMU3100I: Reading configuration for server: server1
0 EJB timer tasks found

I don't know how you are 'redeploying' your applications, but looks like your process is incorrect. As in normal install/uninstall/update process automatic timers are correctly removed.

UPDATE
On the same page you have info regarding ND environment:

Automatic persistent timers are removed from their persistent store when their containing module or application is uninstalled. Therefore, do not update applications that use automatic persistent timers with the Rollout Update feature. Doing so uninstalls and reinstalls the application while the cluster is still operational, which might cause failure in the following cases:

  • If a timer running in another cluster member activates after the database entry is removed and before the database entry is recreated, then the timer fails. In this case, a com.ibm.websphere.scheduler.TaskPending exception is written to the First Failure Data Capture (FFDC), along with the SCHD0057W message, indicating that the task information in the database has been changed or canceled.

  • If the timer activates on a cluster member that has not been updated after the timer data in the database has been updated, then the timer might fail or cause other failures if the new timer information is not compatible with the old application code still running in the cluster member.

Plunge answered 14/2, 2015 at 11:52 Comment(3)
Thanks. I will ask the WAS admins to check this on the servers - I am sorry, but I don't really know what the difference between uninstall vs. undeply is, but our WAS admins keep insisting that they have been doing undeploy for years - since WAS 5, and to uninstall, we need to justify why that is needed, so I am trying to gather information - in the meantime, I will also try this on my local RAD - but I may not know how it behaves on ND, even if I can do it on my local set-up. One question - If I do ADD / Remove from RAD, is that considered uninstall or do I have to use admin consode.Avitzur
@Avitzur You may do it in RAD, Add/Remove is similar to uninstall. You have to gather more details from your admins, what they are doing, as there is no 'deploy`Plunge
Thanks Gas. I requested our websphere admins to cancel the existing EJBTimer for this application and then redeployed the application to our DEV ND environment. That seems to have stopped the continuous running of the timer.Avitzur
T
0

In JBoss/WildFly, if you change the timer-service to use a "clustered-store" instead of "default-file-store", you'll be able to programmatically cancel a Timer. Here is a brief guide explaining how to make it:

Mastertheboss.com: Creating clustered EJB 3 Timers
Published: 08 March 2015
http://www.mastertheboss.com/jboss-server/wildfly-8/creating-clustered-ejb-3-timers
Tern answered 22/2, 2018 at 22:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.