1Z0-900 · Question #33
Given: You are creating an Alarm management system. When you create a new alarm, you want it to create an alert that is triggered once at the specified time. Which method should you call on Line 9 to
The correct answer is D. timerService.createTimer(alarmDate, -l, config);. timerService.createTimer(alarmDate, -1, config) is the correct legacy EJB Timer Service method for creating a one-time timer - passing -1 as the interval duration tells the container not to repeat the timer after its initial firing at alarmDate. Option A (createCalendarTimer) req
Question
Given:
You are creating an Alarm management system. When you create a new alarm, you want it to create an alert that is triggered once at the specified time. Which method should you call on Line 9 to create the timer?
Exhibit
Options
- AtimerService.createCalendarTimer(alarmDate, config);
- BtimerService.createSingleActionTimer(alarmDate, config);
- CtimerService.createIntervalTimer(alarmDate, -l, config);
- DtimerService.createTimer(alarmDate, -l, config);
How the community answered
(38 responses)- A5% (2)
- B13% (5)
- C3% (1)
- D79% (30)
Explanation
timerService.createTimer(alarmDate, -1, config) is the correct legacy EJB Timer Service method for creating a one-time timer - passing -1 as the interval duration tells the container not to repeat the timer after its initial firing at alarmDate.
Option A (createCalendarTimer) requires a ScheduleExpression (cron-style expression), not a plain Date, making it unsuitable for a simple point-in-time alarm.
Option B (createSingleActionTimer) is from the EJB 3.1+ API and would seem intuitive, but the question targets the older createTimer API where this method is not available - the context (method signatures, parameter types) signals the pre-3.1 programming model.
Option C (createIntervalTimer) is semantically wrong regardless of the -1 argument - it is designed for repeating timers and expects a valid positive interval duration.
Memory tip: Think of the -1 as a "null interval" - it's a sentinel value telling the EJB container "fire once, then stop." If you see createTimer(Date, long, Serializable) with a negative second argument, that negative value is the clue that it's a single-action timer in the legacy API.
Topics
Community Discussion
No community discussion yet for this question.
