Question

I can invoke EJB Scheduler using XML (Or I can do with @Schedule annotation). For instance something like this: [ejb-jar.xml]

   <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
        <enterprise-beans>
            <session>
                <ejb-name>[name]</ejb-name>
                <ejb-class>[path]</ejb-class>
                <session-type>Stateless</session-type>
                <timer>
                    <schedule>
                        <minute>*/30</minute>
                        <hour>*</hour>
                        <month>*</month>
                        <year>*</year>
                    </schedule>
                    <timeout-method>
                        <method-name>[method name]</method-name>
                    </timeout-method>
                </timer>
            </session>
        </enterprise-beans>
    </ejb-jar>

If I need to run this Scheduler every day at mid night should I write something like this?

  <schedule>
      <minute>*</minute>
      <hour>0</hour>
      <month>*</month>
      <year>*</year>
  </schedule>

and If I need to 01:00 AM, will this be correct?

  <schedule>
      <minute>*</minute>
      <hour>1</hour>
      <month>*</month>
      <year>*</year>
  </schedule>

thanks :)

Was it helpful?

Solution

For every day at midnight would be something like:

<schedule>
  <minute>0</minute>
  <hour>0</hour>
</schedule>

Every day at 1:00 AM:

<schedule>
  <minute>0</minute>
  <hour>1</hour>
</schedule>

Keep in mind that * is a wildcard meaning all possible values for a given attribute, I omitted month and year since their default value is * and you could actually omit the minute cause its default value is 0.

For every minute of every day:

<schedule>
  <minute>*</minute>
  <hour>*</hour>
</schedule>

For every 10 seconds of every minute of every day:

<schedule>
  <second>*/10</second>
  <minute>*</minute>
  <hour>*</hour>
</schedule>

x/y means every y starting from x, and */y means every y starting from 0.

From your examples, something like these:

<schedule>
  <minute>*</minute>
  <hour>0</hour>
  <month>*</month>
  <year>*</year>
</schedule>

means every day for every minute between 12:00 AM to 12:59 AM, i.e. 12:00, 12:01, 12:02...

For more info, check this link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top