I need to develop the following Java solution and I would like to double-check here that my approach is correct.

At the very basic level, I need the solution to (1) perform an automated activity at the same time every day. This requires no user input. (2) perform the same activity on an ad-hoc basis which is triggered by a user from a web application.

The solution will have two components. Firstly, a Java Windows service that performs the activity. Secondly, a simple Java Spring web application that will be used to trigger the service’s activity on an ad-hoc basis by the user. The web app will communicate with the Windows service through web services exposed by the Windows service. Both the Windows service and the web app will reside on the same server.

If this ‘activity’ was always triggered manually by a user, I’d have no problem incorporating it into a standard Spring web app. However, because I need it to be triggered automatically at the same time every day, my assumption is to separate it out of the web app and into a Windows service.

Is my design appropriate? Any feedback is welcome.

  • 1
    Questions containing words like "correct" and "appropriate" are unanswerable, unless you include specific criteria for what you consider "correct" or "appropriate." In general, there is no such thing as "correct" or "appropriate" in computing; there is only that which best meets your specific requirements. – Robert Harvey Sep 7 '16 at 14:07
  • "Correct" is hard to prove in our field. That said, I have solved similar issues by exposing an API call which performs the work, and having both the webpage and the automated service just both make that call. It seemed to work out well enough. – aaron Sep 7 '16 at 14:12
  • If the web-app is running continuously, why do you need to separate the recurring task out? Is the reliability of the web-app not good enough? Seems to me Timer.scheduleAtFixedRate() would be suited for that. – Marco Borchert Sep 7 '16 at 14:34

Why not just schedule your task within your web application ?

Your task entry point would be triggered by

  1. your timer/scheduler. you can use something like Quartz or just a simple TimerTask. As highlighted below, Spring Tasks may be appropriate if you have Spring already
  2. your web form (REST endpoint, whatever)

and your task would run within a separate thread but within the one JVM.

  • If my memory serves, to launch Quartz's jobs manually is quite tricky. Is not easy and polite to do. Being Spring around, there's Spring Tasks. It works with Timers. It also allows Cronn expressions. The point is to encapsulate well the business make it portable up to the tasks and to any business layer in the web app. – Laiv Sep 7 '16 at 19:28
  • For more features there's Spring Batch. It works over Spring Tasks. – Laiv Sep 7 '16 at 19:33
  • I wouldn't launch a Quartz job manually - rather the task underlying it. But I take your point re. Spring Tasks and have amended my answer, thanks – Brian Agnew Sep 8 '16 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.