user1454674
user1454674

Reputation:

Programmatic timers and Automatic timers - difference

I' want to find difference between that Timer Services. and which should I use and when. I'm using Jboss Application Server.

is 2 and 3 the same? that is difference between Programmatic timers and Automatic timers? is quartz-scheduler implementation Schedule? does they make the same job?

Upvotes: 1

Views: 2164

Answers (2)

Gabriel Aramburu
Gabriel Aramburu

Reputation: 2981

EJB 2.1 Java 1.4

The ejbTimer has to implement TimedObject interface. The TimerService has to be accessed through EJBContext(). The business logic has to be placed in ejbTimeout() method.

EJB 3.0 Java 5

Now, the TimerService can be accessed using Dependency Injection with the annotation @Resource TimerService. The business logic can be placed at any method annotated with @Timeout

The previous versions are called Programatic timer.

EJB 3.1 Java 6

Automatic Timer appears, this means that now you don't have to care about how to get the TimerService due to the ejb container will do the job. The business logic has to be placed at any method annotated with @Schedule or @Schedules, this annotation also allows to add the timer execution period. (in the previous versions this kind of configuration is placed in xml files)

Quartz is not part of Java EE specification.

Upvotes: 1

iskramac
iskramac

Reputation: 868

1) You can use @Schedule annotation on any business method of your EJB, but timer cannot be created dynamically then.

2) When you mark method with @Timeout annotation, it will be invoked when problematically created timer will be triggered. Metadata for triggered timer is in Timer object.

3) TimedObject interface is an alternative to @Timeout annotation, as TimedObject interface contain ejbTimeout(Timer timer) method.

is 2 and 3 the same?

2 and 3 are generally the same,

that is difference between Programmatic timers and Automatic timers?

difference is in the way you create them (with @Schedule annotation there is a limited functionality, as you cannot pass custom object).

is quartz-scheduler implementation Schedule? does they make the same job?

Quartz scheduler is a powerful framework, but no so well integrated with Java EE6 as Timer objects. I prefer EJB Timers, and use quartz only when I need some extra features (e.g. cron expressions).

Upvotes: 1

Related Questions