Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes 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
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Question on Schedule Execution of Business Logic using Automatic Timers

 
pioneer
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Source 12.1.3. Running the Example Program – Declarative Scheduling

OCP JavaEE 6 EJB Developer Study Notes by Ivan A Krizsan Version: April 8, 2012



I had modified the example on Eclipse as below:


@Schedule(second = "20, 45", minute = "*", hour = "6-23",
dayOfWeek = "Mon-Sun", dayOfMonth = "*", month = "*", year = "*",
info = "MyTimer")
private void scheduledMethod1(final Timer inTimer)



Below is the output :



As written in the explanation for the example,

scheduling collisions are resolved by GlassFish by creating a new instance of the stateless session bean and invoking the timeout callback method to be executed next on the new instance



Question 1-A:When it is decided to create a new instance ?
As seen in the output provided,the new instance is created when a new timeout callback method is to created. eg:

scheduledMethod1 is executed with a different instance after scheduledMethod2 is executed

Question 1-B:So,when will the next instance be created ?

I see that both the methods keep on executing with instance 2 and 3 in a random order.
Question 2:So,will these methods stop executing after the criteria in the cancelOverdue is met or there is any other way too ?

I have configured the hour to be hour = "6-23".
Question 3 :So, shouldn't the timer till run 23 hr ? ( I see it running past 23 too,Please see in the output provided)
 
Mohit G Gupta
pioneer
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please advise.
 
Creator of Enthuware JWS+ V6
Posts: 3321
298
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohit,

Question 1-A:When it is decided to create a new instance ?


It has to use an idle instance for every timeout, so if all instances are serving a client (timeout), it will create a new one to serve the timout.

Question 2:So,will these methods stop executing after the criteria in the cancelOverdue is met or there is any other way too ?


No, they will just keep on expiring. Timers are also persisted, so even when you stop and start the server they will just keep on going to expire.

So, shouldn't the timer till run 23 hr ? ( I see it running past 23 too,Please see


Yes they should, but I guess the timer expired before 23 hrs and the log statement is only printed 15 seconds later (see waitSeconds(15);)

Regards,
Frits
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!