這篇不是真正教如何設計Java Daemon,考量如何利用別人寫好的Java Daemon能夠比較容易整合於不同環境中。 如通常不會自行開發工作排程系統,利用已成熟Quarts為基礎往上堆應用程式,雖然是已成熟Java Daemon要如何整合於不同的作業系統(Linux, Windows, Mac) ?
這個問題說難不難說簡單不簡單,解決方案也五花八門。傳統方式就是撰寫 public static void main(String[]) 統一由這一支Java程式啟動服務,然後撰寫一堆shell呼叫, 雖然問題也是可以解決但是往後系統維護管理不易也沒有統一。
Apache Commons Daemon 專案滿不錯解決方案之一
...Most multi-user operating systems already have a way in which server applications are started and stopped. Under Unix based operating systems non interactive server applications are called daemons and are controlled by the operating system with a set of specified signals. Under Windows such programs are called services and are controlled by appropriate calls to specific functions defined in the application binary, but although the ways of dealing with the problem are different, in both cases the operating system can notify a server application of its imminent shutdown, and the application has the ability to perform certain tasks before its process of execution is destroyed.