"When to shut down" a daemon job is always a trick.
It depends on the application, I think. Are you planning on having your
entire application reside in a single JVM, and have the command processor
slaved to that JVM? Is there a clean shutdown for the Java application? Do
you need to handle situations where the JVM is brought down dirty? Are
there situations where you might need more than one server (for instance,
long-running command and high-priority short commands)?
All of these types of questions come into play when you're designing your
shutdown logic. However, the basic idea of a timeout on the read combined
with an exclusive lock on an object are a good general combination, no
matter what the specifics are.
Joe