aspose file tools*
The moose likes Java in General and the fly likes Job Scheduling in Java - need tips and suggestions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Job Scheduling in Java - need tips and suggestions" Watch "Job Scheduling in Java - need tips and suggestions" New topic
Author

Job Scheduling in Java - need tips and suggestions

David S Hansen
Ranch Hand

Joined: Mar 07, 2013
Posts: 30
I want to make a job scheduler (GUI/Swing based) which will do certain tasks on a regular basis. Sometimes these tasks can be prevented from happening as per their normal schedule. After that interruption is over, the jobs will run according to their normal schedule.

I don't know what is the best and simplest way to do these things. I saw that Timer and TimerTask can do similar things. But I don't know if those classes have any limitations.
I also looked at Quartz. But, it is too sophisticated and complex for my simple program.

Are there any other simple and reliable options out there ? If not, how do I learn about Timer and Timer Task to make my program.

Thanks in advance.

Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
David S Hansen wrote:how do I learn about Timer and Timer Task to make my program.

You google 'java timer tutorial'

Joanne
David S Hansen
Ranch Hand

Joined: Mar 07, 2013
Posts: 30
Joanne Neal wrote:
David S Hansen wrote:how do I learn about Timer and Timer Task to make my program.

You google 'java timer tutorial'


I did that and all the tutorials are silly toy examples and nothing more. I am trying to avoid sophisticated stuff like cron4j and quartz. What do I do ?
Is there any book that explains Timer well with some good examples ?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

You could also take a look at java.util.concurrent.ScheduledExecutorService; see this section of the concurrency tutorials: http://docs.oracle.com/javase/tutorial/essential/concurrency/exinter.html


Junilu - [How to Ask Questions] [How to Answer Questions]
David S Hansen
Ranch Hand

Joined: Mar 07, 2013
Posts: 30
UPDATE

I feel that Timer and TimerTask are good enough for my purposes, but too basic for big jobs. I am thinking of learning a scheduler api, but I am not sure which one to select.
I have the following criteria to choose my api -

1 - Must be very easy to use - no complicated setup, no additional skills except java needed (ie NO xml, json, ant, maven etc)
2 - Should be popular among developers, mature, well maintained, have well documented API.
3 - Should have a lot of tutorials and/or books especially for beginners (ie those just beginning job scheduling)

Nice to have - Eclipse integration (if applicable)

Please help me to evaluate all the good options out there like cron4j, quartz, obsidian.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Of the three options you cited, I have only worked with Quartz, so take this with a grain of salt. cron4j seems to fit the bill for minimalism so you might want to start with that and work your way up to Quartz and/or Obsidian as your scheduling needs expand and get more sophisticated. From what I've seen with a cursory exploration of their website, Obsidian offers many features that make it easier to set up, manage, and monitor your jobs. Quartz is probably the more commonly used of the three and there are many references and tutorials on using it but there is still a bit of a learning curve involved, based on my experience.

Hope this helps
David S Hansen
Ranch Hand

Joined: Mar 07, 2013
Posts: 30
Junilu Lacar wrote:Of the three options you cited, I have only worked with Quartz, so take this with a grain of salt. cron4j seems to fit the bill for minimalism so you might want to start with that and work your way up to Quartz and/or Obsidian as your scheduling needs expand and get more sophisticated. From what I've seen with a cursory exploration of their website, Obsidian offers many features that make it easier to set up, manage, and monitor your jobs. Quartz is probably the more commonly used of the three and there are many references and tutorials on using it but there is still a bit of a learning curve involved, based on my experience.

Hope this helps


Yes, cron4j seems to fit my description. But, there is hardly any documentation, tutorial, or presence on forums like CodeRanch, StackOverflow, ExpertsExchange. So, I will have almost no help for cron4j. Quartz seems better in that respect. But its like using a pistol to kill a fly. IMHO, in the end documentation and tutorials trump everything, given that features are ok and software is usable.

So, can you tell me if the following is true -


Using Quartz is as simple as downloading the necessary file and adding the jars in that file to your project. There is nothing else to Quartz, besides learning how the API works.
There are no new/extra things like config files (xml, json). No ant or maven knowledge is necessary.

If that is true, then quartz is my choice. Obsidian sounded much better because it talked about doing away with xml config and such. But, its too new, unproven and has "0" support on public forums.

EDIT -


It looks like you need to know SLF4J as per sl4fj page and this tutorial
Is it really needed for all quartz projects ?



Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7063
    
  16

David S Hansen wrote:Yes, cron4j seems to fit my description. But, there is hardly any documentation, tutorial, or presence on forums like CodeRanch, StackOverflow, ExpertsExchange. So, I will have almost no help for cron4j.

I'm not so sure about that. The name would suggest that cron4j is a Java port of the Unix cron command (which, IMO, is a classic piece of minimalist software); and there is plenty of documentation about that around. As an old Unix SA, it would certainly be my first port of call if simplicity was my main concern.

My only question would be: what does it run? Unix cron is designed for running system commands/scripts, so I'm guessing that there's probably some sort of translation between a "name" in your 'crontab' (== config file) and a Java Runnable; but exactly what that is I don't know.

Winston

PS: I've just had a quick look at the documentation, and it seems perfectly reasonable; and very straightforward. Everything is based around a Task class which you extend. The API docs are a little weak, but there seems to be more than enough to get started in the main docs.

Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
David S Hansen
Ranch Hand

Joined: Mar 07, 2013
Posts: 30
Winston Gutkowski wrote:
David S Hansen wrote:Yes, cron4j seems to fit my description. But, there is hardly any documentation, tutorial, or presence on forums like CodeRanch, StackOverflow, ExpertsExchange. So, I will have almost no help for cron4j.

I'm not so sure about that. The name would suggest that cron4j is a Java port of the Unix cron command (which, IMO, is a classic piece of minimalist software); and there is plenty of documentation about that around. As an old Unix SA, it would certainly be my first port of call if simplicity was my main concern.

My only question would be: what does it run? Unix cron is designed for running system commands/scripts, so I'm guessing that there's probably some sort of translation between a "name" in your 'crontab' (== config file) and a Java Runnable; but exactly what that is I don't know.

Winston

PS: I've just had a quick look at the documentation, and it seems perfectly reasonable; and very straightforward. Everything is based around a Task class which you extend. The API docs are a little weak, but there seems to be more than enough to get started in the main docs.


I guess its enough to get started. Lets compare the two API's on the basis of StackOverflow data -

Quartz -

Quartz questions
Quartz unanswered

Cron4j -

Cron4j Questions
Cron4j Unanswered

As of now -

Questions: Cron4j = 6, Quartz = 965
Unanswered: Cron4j = 3, Quartz = 259
fail rate: Cron4j = 50, Quartz = 27%

Looks like cron4j is a BIG loser in terms of support. I think that beginners need support the most, especially in the form of quick responses at any time of the day, something that one usually finds only in SO (Sorry coderanch) .

However, it is possible that cron4j is so simple and intuitive that people don't really need to ask questions and Quartz is super complicated.

My problem is that I have no way to be sure if the above line is true. If not, then cron4j might be a bad choice for a beginner.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7063
    
  16

David S Hansen wrote:However, it is possible that cron4j is so simple and intuitive that people don't really need to ask questions and Quartz is super complicated.
My problem is that I have no way to be sure if the above line is true. If not, then cron4j might be a bad choice for a beginner.

Possibly, unless they
(a) already know cron.
(b) don't need great complexity.
in which case I suspect it would be a very natural choice. It seems like a pretty straightforward port of the command to me.

Winston
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

David, can you be more specific about the details of the job(s) are you trying to schedule? I'm starting to think that we could go into a fairly long discussion about the pros and cons of each of these frameworks. If we had a better idea of what the exact problem was, it would help limit the scope of the discussion and get to a decision quicker.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Moving thread as too difficult for “beginning”.
David S Hansen
Ranch Hand

Joined: Mar 07, 2013
Posts: 30
Junilu Lacar wrote:David, can you be more specific about the details of the job(s) are you trying to schedule? I'm starting to think that we could go into a fairly long discussion about the pros and cons of each of these frameworks. If we had a better idea of what the exact problem was, it would help limit the scope of the discussion and get to a decision quicker.


I want to perform simple tasks (eg. download file, upload, etc) at particular times in a day, everyday. I want to have the power to change these times depending on my needs on a particular day. I need a scheduler for this purpose.
Is this information enough answer the question?

Komal Renu
Ranch Hand

Joined: Jul 21, 2011
Posts: 51
David,

I've used the Quartz API in quite a complex project. And Quartz is fairly simple, right from setting it up to extending the API for customizations.
And it is very stable and reliable in terms of job executions. Maintains its own DB which enables easier monitoring or altering of jobs.

My say would be Quartz.
If at all you decide to use the Quartz API, we can then take forward your questions.

Thanks and Regards,
-------------------------------------------------------------------------------------
Komal Renu | krenu@infocepts.com | www.infocepts.com
-------------------------------------------------------------------------------------
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

David S Hansen wrote:I want to perform simple tasks (eg. download file, upload, etc) at particular times in a day, everyday. I want to have the power to change these times depending on my needs on a particular day. I need a scheduler for this purpose.
Is this information enough answer the question?

Then I'd say that scheduling is not the big problem here. If this was my project, I'd probably just use the Spring Framework's TaskScheduler and a CronTrigger. However, of the choices you have narrowed it down to, I would probably go with cron4j because it seems to be the simplest and most straightforward of the three.
David S Hansen
Ranch Hand

Joined: Mar 07, 2013
Posts: 30
Junilu Lacar wrote:
David S Hansen wrote:I want to perform simple tasks (eg. download file, upload, etc) at particular times in a day, everyday. I want to have the power to change these times depending on my needs on a particular day. I need a scheduler for this purpose.
Is this information enough answer the question?

Then I'd say that scheduling is not the big problem here. If this was my project, I'd probably just use the Spring Framework's TaskScheduler and a CronTrigger. However, of the choices you have narrowed it down to, I would probably go with cron4j because it seems to be the simplest and most straightforward of the three.


Now the choice is between cron4j and ScheduledThreadPoolExecutor. What should I take ?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Either one is fine but in the end the choice is really up to you. If it were me, I would probably go with the Executor since it's from the standard library.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
I have found Timer and TimerTask to be sufficient even for apps that consist of little else but running scheduled jobs.

Why do you want a GUI to be involved? Most scheduled jobs are of the non-GUI variety, making them amenable to be run by trusty old cron invoking a JVM.

If I found these lacking I'd probably go for Quartz, simply because it seems the standard library for the job, so I'd assume it's well-tested and I can find someone to answer questions.


Ping & DNS - updated with new look and Ping home screen widget
Obsidian Support
Greenhorn

Joined: Aug 02, 2013
Posts: 1
David S Hansen wrote:
If that is true, then quartz is my choice. Obsidian sounded much better because it talked about doing away with xml config and such. But, its too new, unproven and has "0" support on public forums.



You describe Obsidian as too new and unproven. Obsidian Scheduler has been around for more than 2 years, so it is newer than some of these solutions, but is already in use by thousands including Fortune 500 companies. As far as public forums, we provide free support by phone, email and live chat in addition to our extensive wiki that documents the scheduler extensively. As new issues and questions come up and are addressed, the wiki is extended. Try it out we think you'll be most impressed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Job Scheduling in Java - need tips and suggestions
 
Similar Threads
Develop automatic B'Day mailer in java
Timer, Again
Thread and Timer
Using Quartz in web application
questions java.util.Timer