Java Reference
In-Depth Information
on the @Schedule annotation are typed as strings and not integers. This is because you
can provide expressions to attributes for constructing complex schedules. For example, you
could create a timer that executes only Monday through Friday or a timer that executes
every other week. If you were limited to single values or the scheduling capabilities prior
to EJB 3.1, you wouldn't be able to easily implement this functionality. The attributes sup-
port the following syntax forms: single value, wildcard, list, ranges, and increments.
Single value
Single values are the most straightforward and easiest to understand. Table 7.1 lists the
valid values that can be used for each attribute. The values are case-insensitive. For some
attributes, there are two representations—either numeric or text—as in the case of days of
the week where Monday can be represented as either "Mon" or "0" . The following are
some examples of setting an attribute to a single value:
@Schedule(second="0", minute="1", hour="23", dayOfMonth="1", month="Apr",
dayOfWeek="Mon", year="2015")
In this example, a timer is created that will execute on at 11:01:00 on the first day of April
and the first Monday of April if the year is 2015. This expression is somewhat deceiving
because the dayOfMonth and dayOfWeek are combined using an or , whereas the oth-
er attributes are combined using a logical and . Thus, this expression will fire on April 1,
2015, and April 6, 2015.
Wildcard
The wildcard * matches all possible values for a given attribute. If you've used either ls
on Unix or dir on Windows, this should be familiar. The wildcard is used in situations
where you want the expression for an attribute to match all possible values but you don't
want to list all of the values. The wildcard can be used on all attributes but in most circum-
stances it's not advisable to use it on second and minute . Running a task every second
or every minute will have an adverse impact on system performance. Frequent polling in
an Enterprise application reduces scalability and responsiveness. Let's look at an example
using the wildcard:
@Schedule(second="*", minute="*", hour="*", dayOfMonth="*", month="*",
dayOfWeek="*", year="*")
Search WWH ::




Custom Search