Heyap, here's my design problem:

I need to updated stuff in a datebase all the time. The process takes now from 1 to 7 minutes per update. I've a Producer that udpates an update list once a day, and a Consumer that checks for items on the list and takes one to be updated, if available.

Currently the Consumer is started from the cron, and it takes just the one item, updates it, marks it as updated on the update list, and exits. Thus even if something goes very wrong, the next Consumer will be started as scheduled, and nothing bad happens. If the Consumer can, it will save the result of a failed processing in the update list; so if there's something wrong with an item to update, it can just skip it and go on with the next one.

But now the customer want's the Consumer to run as frequently as it can. And so here's...

The problem (finally):#

What kind of mechanism should I use to make a bullet-proof watchdog-process in Java? I can use the cron, but I don't want to use any os-specific methods for checking if my process is running. I could make a server socket, and check that every once in a while, and start a new process if the old one has died. However what if the socket dies, or either of the threads die? Multiple Consumer processes should not be running simultaneously!

TIA, AnttiR


How about if your Consumer process touches a temporary file (using File.setLastModified()) every now and then?

You could then run a watchdog process from the cron, which would check the last modification date of the temporary file and start a new process if it has not been touched for X minutes?

This may be problematic if your Consumer process blocks for a long time.

--JanneJalkanen


Oh well, I already implemented it with the server-socket-in-another-thread method. It should be pretty certain, anyway. Thanks anyway.

Oh and hey, if someone happends to have a problem with starting a new process with the watchdog, here a solution: if the process is dead, return an error code, and start the new process in the script that launched the watchdog. That's simple, safe and os-independent.

AnttiR


Wrapper can be considered as a probable solution

-- MalLim

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-14) was last changed on 16-Feb-2004 23:42 by JanneJalkanen