Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multithreading or cronjob

I have folders which contain xml files. The content of folders is updated (inserted new xml files) as N files per day. I would like to write java program which will get the newest files from folders and do some operations with these files. I have two ways of doing this:

  Run java application every t minutes with cronjob.

or

Multithreaded java application which is run as daemon.

Which will be more efficient? Or any ideas, which can help.

Application should run on Linux.

like image 864
torayeff Avatar asked Nov 13 '22 15:11

torayeff


1 Answers

Even if you decided not to go the cron route, your Java application probably wouldn't need to be multithreaded, unless you ended up building a Quartz-like scheduler from scratch (which would probably be overkill).

I recommend going with the cron approach for several reasons:

  1. Cron is appropriate for the requirements which you've given (i.e. periodic execution without the need to process files as soon as they're received).
  2. You're more likely to have bugs around scheduling if you code that logic yourself rather than rely on cron, which is tried and tested.
  3. If you use cron and your Java application crashes for some reason, then it won't affect subsequent executions. If you decided to use a long-running Java daemon however, you would probably have to implement a mechanism to monitor its health.
like image 139
Mansoor Siddiqui Avatar answered Nov 15 '22 06:11

Mansoor Siddiqui