Scheduler and Business Logic Separation

Splitting a scheduler:

public class Reminder {

    CoffeeBrewer brewer;

    @Schedule(minute = "*/30", hour = "*")
    public void remind() {

...and the business logic:

public class CoffeeBrewer {

    public void brew() {

    void boil() {}
    void grind() {}
    void deliver() { }
    void pay() {}

...into separate classes (dedicated boundary and control) allows the application server to inject proxies. Proxying comes with following benefits:

  1. Fine grained transaction management: business logic (CoffeeBrewer) can use declarative transactions as usual
  2. Monitoring: application server will expose monitoring statistics for both classes
  3. Interception: individual interceptors can be use on both: the scheduler as well as the business logic
  4. Less noise: dynamic/flexible Schedulers require additional configuration logic. With scheduler / business logic separation, the business logic class remains unaffected and clean.
  5. Easier unit testing: there is no scheduling code in the business logic

...and the downside? You have to write one more class...

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home:

NEW MUC Airport Workshop: Migrating Java Client (Swing / Java FX) to Web Standards

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: and newsletter:

A book about rethinking Java EE Patterns


Very useful!
For the 2nd benefit, the monitoring exposition, is it for the last versions of JBoss and Glassfish?
And is it by JMX?

Posted by Fred on September 24, 2017 at 05:16 PM CEST #

An example of a database/ configurable timer/scheduler would be greatly apreciated

Posted by litts on September 25, 2017 at 07:32 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments