Question

I have a complex web application on java. It contains:

  1. different library modules that stores and manages by maven
  2. web module that scale to many servers in the cloud
  3. database: sql + nosql
  4. many different scheduled jobs to work with database.

I need advise how to develop and manage this scheduled jobs. My requirements:

  1. Jobs should be separated from web module because web tier are automatically scales on amazon ec2 insanses.
  2. Some of jobs do very important work with money, so i need a really good tools for monitoring job results,job states, logs and etc. I need a ability for make very quick hotfixes and ability to stop\start\cancel(if it freezes for some reason) specific jobs separately in real time.
  3. I need to use continuous delivery(CD) when all works right. That means jobs builds on CI server and deployed to test\production server automatically. Configuration of scheduled time must be under version control too.

I looked on some solutions:

  1. jobs servers like obsidian. Do not think that is good idea to use a monster solution like this.
  2. quartz. I Can not find a simple way how to merge the requirements number 2 and 3. With quartz i can manage my jobs in real time or make a good CD build for jobs. Not together. Maybe i am miss something ?
  3. Deploy job jars to destination server with all libraries and run scripts Run that scripts from cron. This solution looks ugly. Firstly i need to deploy to test\production server all my libraries from CI server on every deploy to maintain CI process clean. Secondly i don really think that is a good idea at all. I really think that i am miss something and there is a good solution for this usual problem.

Can you give me advice ? How developers manage scheduled jobs with CD process usually?

Was it helpful?

Solution

I am considering you must be using some application server like JBoss or WebLogic.

I would suggest write a Service MBean which would load your scheduled jobs using quartz

Benefit of using Service MBean, you can expose actions. Calling these actions you should be able to stop start the job.

Benefit of QuartZ is it is very reliable. You will be able to manage individual jobs.

Catch here is there will be only one instance of scheduler (object) under your Service MBean. So if you stop the scheduler you stop all the jobs.

You can create a separate logger category to work out with the QuartZ job

Please provide some more inputs like which application server you are using. Different application server have different features which may be useful. Though you should be able to implement all your ideas in any of them

I have a similar application running on JBoss AS7, each job is a thread on its own In the execute logic of the Job, I do

Thread.currentThread().setName(UNIQUE_NAME_TIMESTAMP);

in this way I am able to mark the specific job's execution per cycle.

quartz. I Can not find a simple way how to merge the requirements number 2 and 3. With quartz i can manage my jobs in real time or make a good CD build for jobs. Not together. Maybe i am miss something ?

You really need a application server like JBoss. which can provide you a stable web container, is fully Java EE certified, eases your API integration.

----==----==---==----==---==----==---==----==---==----==---==----==----

I hope you know how to write SARs. If not still it is very easy. I like JBoss as its concept is simple, is easy to use and it is very strong Application Server.

You can check this particular tutorial blog to understand how to write service MBean http://middlewaremagic.com/jboss/?p=366

Lets talk about the MyServerMonitorMBean

package custom.mbean;
public interface MyServerMonitorMBean
{
  public void setFrequency(String frequency);
  public String getFrequency();
}

as you would have noticed there are method declarations which needs to be implemented the implementation of MBean.

In Java EE architecture what this means is you are actually exposing actions. Actions which can be called from outside to invoke some commands. Now only methods which have been declared in the interface MBean have this concept.

Then you can connect to the JBoss JMXconsole via jconsole. You can check that here

https://community.jboss.org/wiki/UsingJconsoleToConnectToJMXOnAS7

----==----==---==----==---==----==---==----==---==----==---==----==----

--1-- This will open up connection which will allow you to view running MBeans over the server (that would be MBean tab of the JConsole after connection)

--2-- your mbean will be service.server.monitor (name taken from previous example)

--3-- you will find the actions showing up as operations

--4-- if you have declared the methods to have some arguments you will see there is individual value holder for those method arguments which you can pass to the service

--5-- in my code I had exposed jobStart and jobStop as two actions

@Override
public void jobStart() {
    this.loadJob(SchedHourlyJob.class, "hourlyjob", "grouphourly", START_INTERVAL, EXECUTION_INTERVAL);
}

@Override
public void jobStop() {
    logger.info("-- jobStop. Stopping Scheduled Job");

    try {
        scheduler.deleteJob(new JobKey("hourlyjob", "grouphourly"));
    } catch (SchedulerException schedEx) {
        logger.error("Failed to stop scheduled job. Exception message and stacktrace  ==> " ,schedEx);
    }
}

--6-- Expose similar actions to start stop or change the individual job or complete scheduler.

--7-- You will also be able to pause the job induce some change and start it back. All these manipulation makes Quartz such a nice API for job scheduling

--8-- In JBoss hot deployment is possible. You can have you application in multiple sar's which will share common libraries. You can do testing around these features of JBoss. I understand hot deployment is something you will be highly focusing at.

I hope with all this I explained the logic pretty well. Also this is one way of handling this, you can come up with something of your own as well.

Remember implementation is your way of handling the requirement.

And just now I thought, making class name, job name can form a very generic way of stopping or pausing the jobs from a common class (Service MBean). As I said earlier these all ideas needs to be tested. Therefore I am considering if get the hang of it you would be able to come up with a good solution

And Once more thinking, you can even implement the call of actions by JMS, Write a model class form its object and send it to your server. But then again you can always frame a way to stop your job.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top