Themes in a Java EE Application

I have a Java EE application that has two components. First, it's a service that dumps some information from the internet and populates it in the database. Second, it's a web interface (deployed to tomcat) from where the user can view this information.

What might be the best approach to implement the first component? Should it run as a Daemon / Service background or a thread inside a container?

+2


source to share


3 answers


I would personally separate them into different processes. Among other things, this means that you can restart it without worrying about anything else. This also means that you can really easily deploy them to different machines without aimlessly installing Tomcat for a service that doesn't actually need a web interface.



+8


source


Depending on the type of framework, Spring allows you to use Quartz or a framework java.util.concurrent

. Spring has an abstraction TaskExecutor

(see Spring documentation ) that simplifies a lot of this, but check out which approaches are best with your design.

Spring or Quartz (managed by Spring) then manages the creation and starting / stopping of threads or executors or jobs, as well as their frequency / period and other scheduling parameters, and also manages any pool of jobs you might require.



I use them for all my background tasks and batch jobs in any Java EE applications that I write without issue. Since Jobs are Spring managed POJOs, they have access to the full dependency injection infrastructure, etc., which is what Spring implies, and of course you can switch between scheduler frameworks with a simple change to your application config XML file as yours needs change or scale.

+7


source


There is nothing wrong with having background jobs inside the web container, but you MUST let the web container know so that it can be stopped and started correctly.

Take a look at the load-on-startup tag in web.xml. There are some tips on http://wiki.metawerx.net/wiki/Web.xml.LoadOnStartup

+2


source







All Articles