DevOps研发效能
媒体矩阵
开源中国APP
授权协议 Apache
开发语言 Java C/C++
操作系统 Windows
软件类型 开源软件
所属分类 程序开发常用工具包
开源组织 Apache
地区 不详
投 递 者 小编辑
适用人群 未知
收录时间 2010-05-17

软件简介

Commons Daemon 可以帮你实现将一个普通的 Java 应用编程系统的一个后台服务。

例如 Tomcat 就是利用这个项目来实现作为 Linux 和 Windows 的服务启动和停止的。

示例代码:

/**
 * Launch the Engine from a variety of sources, either through a main() or invoked through
 * Apache Daemon.
 */
public class EngineLauncher implements Daemon {
    private static final Log4J log = Log4J.getLog();
    private static Engine engine = null;

    private static EngineLauncher engineLauncherInstance = new EngineLauncher();

    /**
     * The Java entry point.
     * @param args Command line arguments, all ignored.
     */
    public static void main(String[] args) {
        // the main routine is only here so I can also run the app from the command line
        engineLauncherInstance.initialize();

        Scanner sc = new Scanner(System.in);
        // wait until receive stop command from keyboard
        System.out.printf("Enter 'stop' to halt: ");
        while(!sc.nextLine().toLowerCase().equals("stop"));

        if (!engine.isStopped()) {
            engineLauncherInstance.terminate();
        }

    }

    /**
     * Static methods called by prunsrv to start/stop
     * the Windows service.  Pass the argument "start"
     * to start the service, and pass "stop" to
     * stop the service.
     *
     * Taken lock, stock and barrel from Christopher Pierce's blog at http://blog.platinumsolutions.com/node/234
     *
     * @param args Arguments from prunsrv command line
     **/
    public static void windowsService(String args[]) {
        String cmd = "start";
        if (args.length > 0) {
            cmd = args[0];
        }

        if ("start".equals(cmd)) {
            engineLauncherInstance.windowsStart();
        }
        else {
            engineLauncherInstance.windowsStop();
        }
    }

    public void windowsStart() {
        log.debug("windowsStart called");
        initialize();
        while (!engine.isStopped()) {
            // don't return until stopped
            synchronized(this) {
                try {
                    this.wait(60000);  // wait 1 minute and check if stopped
                }
                catch(InterruptedException ie){}
            }
        }
    }

    public void windowsStop() {
        log.debug("windowsStop called");
        terminate();
        synchronized(this) {
            // stop the start loop
            this.notify();
        }
    }

    // Implementing the Daemon interface is not required for Windows but is for Linux
    @Override
    public void init(DaemonContext arg0) throws Exception {
        log.debug("Daemon init");
        }

    @Override
    public void start() {
        log.debug("Daemon start");
        initialize();
    }

    @Override
    public void stop() {
        log.debug("Daemon stop");
        terminate();
    }

    @Override
    public void destroy() {
        log.debug("Daemon destroy");
    }

    /**
     * Do the work of starting the engine
     */
    private void initialize() {
        if (engine == null) {
            log.info("Starting the Engine");
 ... spawn threads etc
        }
    }

    /**
     * Cleanly stop the engine.
     */
    public void terminate() {
        if (engine != null) {
            log.info("Stopping the Engine");
            engine.stop();
            log.info("Engine stopped");
        }
    }
}

展开阅读全文

评论

点击加入讨论🔥(2) 发布并加入讨论🔥
发表了资讯
2013/04/04 00:00

Apache Commons Daemon 1.0.15 发布

Apache Commons Daemon 1.0.15 发布了,修复了 1.0.14 中的 bug。 完整记录请看: https://issues.apache.org/jira/browse/DAEMON/fixforversion/12324242 Commons Daemon 可以帮你实现将一个普通的 Java 应用编程系统的一个后台服务。 例如 Tomcat 就是利用这个项目来实现作为 Linux 和 Windows 的服务启动和停止的。...

0
27
发表了资讯
2013/03/20 00:00

Apache Commons Daemon 1.0.14 发布

Apache Commons Daemon 1.0.14 发布,这是个 bugfix 版本。 Commons Daemon 可以帮你实现将一个普通的 Java 应用编程系统的一个后台服务。 例如 Tomcat 就是利用这个项目来实现作为 Linux 和 Windows 的服务启动和停止的。

0
3
发表了资讯
2013/02/13 00:00

Apache Commons Daemon 1.0.13 发布

Apache Commons Daemon 1.0.13 修复了前些天发布的 1.0.12 版本的一些重要 bug。 Commons Daemon 可以帮你实现将一个普通的 Java 应用编程系统的一个后台服务。 例如 Tomcat 就是利用这个项目来实现作为 Linux 和 Windows 的服务启动和停止的。

1
10
发表了资讯
2013/01/24 00:00

Apache Commons Daemon 1.0.12 发布

Apache Commons Daemon 1.0.12 发布了,主要是修复了在 1.0.11 中发现的 bug。 Commons Daemon 可以帮你实现将一个普通的 Java 应用变成系统的一个后台服务。 例如 Tomcat 就是利用这个项目来实现作为 Linux 和 Windows 的服务启动和停止的。

4
46
发表了资讯
2012/11/29 00:00

Apache Commons Daemon 1.0.11 发布

Apache Commons Daemon 1.0.11 发布,修复了 1.0.10 的 bug 而已。 Commons Daemon 可以帮你实现将一个普通的 Java 应用编程系统的一个后台服务。 例如 Tomcat 就是利用这个项目来实现作为 Linux 和 Windows 的服务启动和停止的。

6
17
发表了资讯
2012/02/29 00:00

Apache Commons Daemon 1.0.10 发布

Commons Daemon 1.0.10 是一个 bug 修复版本,主要的问题集中在 Linux 平台下没有使用 libcap 头文件的构建问题。 下载地址:http://commons.apache.org/daemon/download_daemon.cgi

0
0
发表了资讯
2012/02/15 00:00

Apache Commons Daemon 1.0.9 发布

Apache Commons Daemon 刚刚发布了 1.0.9 版本,这是一个 bug 修复版本,修复了一些小问题,下载地址: http://commons.apache.org/daemon/download_daemon.cgi Commons Daemon 可以帮你实现将一个普通的 Java 应用编程系统的一个后台服务。 Tomcat 就是利用这个项目来实现作为 Linux 和 Windows 的服务启动和停止的。...

8
4
发表了资讯
2011/11/24 00:00

Apache Commons Daemon 1.0.8 发布

Apache Commons Daemon 团队刚发布了 1.0.8 版本,该版本包含 bug 修复和一些更新的特性,请看下载包后的 RELEASE-NOTES.txt 文件。 下载地址: http://commons.apache.org/daemon/download_daemon.cgi Commons Daemon 可以帮你实现将一个普通的 Java 应用编程系统的一个后台服务。 例如 Tomcat 就是利用这个项目来实现作为 Linux 和 Windows 的服务启动和停止的。...

1
3
发表了资讯
2011/08/13 00:00

Apache Commons Daemon 1.0.7 发布

Commons Daemon 可以帮你实现将一个普通的 Java 应用编程系统的一个后台服务。 例如 Tomcat 就是利用这个项目来实现作为 Linux 和 Windows 的服务启动和停止的。 1.0.7 版本修复了 CVE-2011-2729 这个安全漏洞。

0
6
发表了资讯
2011/07/14 00:00

Jsvc 1.0.6, Tomcat 后台运行的管理器

jsvc最近已发布1.0.6版本,本次更新添加了很多JVM参数的支持,更新功能详列如下: * DAEMON-209: Add --LibraryPath to procrun for setting the LoadLibrary serch paths (1.0.6) * DAEMON-208: Add -server and -client -jvm <name> synonyms (1.0.6) * DAEMON-205: Add support for building on ARM processors (1.0.6) * DAEMON-204: Add DaemonSignal interface that allows catching SIGUSR2 ...

0
10
发表了资讯
2011/07/09 00:00

Commons Daemon 1.0.6 发布

Apache Commons Daemon 今天发布了 1.0.6 版本,这是一个补丁修复和功能更新版本。 源码和二进制包下载: http://commons.apache.org/daemon/download_daemon.cgi 详细改进记录请看下载包中的 RELEASE-NOTES.txt Commons Daemon 可以帮你实现将一个普通的 Java 应用编程系统的一个后台服务。 例如 Tomcat 就是利用这个项目来实现作为 Linux 和 Windows 的服务启动和停止的。...

0
1
发表了资讯
2010/10/26 00:00

Commons Daemon 1.0.4 发布

Commons Daemon 可以帮你实现将一个普通的 Java 应用编程系统的一个后台服务。 例如 Tomcat 就是利用这个项目来实现作为 Linux 和 Windows 的服务启动和停止的。 下载地址:http://commons.apache.org/daemon/download_daemon.cgi 该版本主要是bug修复,也有一些小改进。

1
5
发表了资讯
2010/08/03 00:00

Commons Daemon 1.0.3 发布-下载

话说这个东西就是影响 Tomcat 7.0.1 版本正常发布的元凶,详情请看这里。 下载地址:http://commons.apache.org/daemon/download_daemon.cgi 该版本主要修正了一个安全性bug,详情请下载并查看 RELEASE-NOTE.txt 文件。

0
0
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
2 评论
215 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部