知识库--StandardService + Lifecycle(start/stop)+initialize(72)

翻译 2017年01月04日 00:31:20

StandardService + Lifecycle(start/stop)+initialize

核心:
//Server提供了一个优雅的启动和停止方法
//Service 封装了container和多个connectors

The lifecycle methods are the start and the stop methods inherited from the Lifecycle interface plus the initialize method.

//initialize method calls the initialize method of each connector

public void initialize() throws LifecycleException{
    if(initialized){
        throw new LifecycleException();
    }
    initialized = true;

    synchronized(connectors){
        for(int i =0;i<connectors.length;i++){
            connectors[i].initialize();
        }
    }   
}

//start method starts the associated container as well as the connector added to this service

public void start() throws LifecycleException{
    if(started)
        throw new LifecycleException();
    //notify our interested LifecycleListeners
    lifecyle.fireLifecycleEvent(BEFORE_START_EVENT,null);
    //...sout
    lifecycle.fireLifecycleEvent(START_EVENT,null);
    started = true;
    //start our defined container first
    if(container != null){
        synchronized(container){
            if(container instanceof Lifecycle){
                ((Lifecycle)container).start();
            }
        }
    }
    //start our defined connectors 
    synchronized(connectors){
        for(int i =0;i<connectors.length;i++){
            if(connectors[i] instanceof Lifecycle){
                ((Lifecycle)connectors[i]).start();
            }
        }
    }
    //notify
    lifecycle.fireLifecycleEvent(AFTER_START_EVENT,null);
}

//stop method stops the associated container and all the connectors

public void stop()throws LifecycleExcetption{
    //validate and update our current component state
    if(!started){
        throw new LifecycleException();
    }
    //notify our interested lifecycleListeners
    lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT,null);
    lifecycle.fireLifecycleEvent(STOP_EVENT,null);
    //sout...
    started = false;
    //stop connectors first
    synchronized(connectors){
        for(int i =0;i<connectors.length;i++){
            if(connectors[i] instanceof Lifecycle)
                ((Lifecycle)connectors[i]).stop();
        }
    }
    //stop container second
    if(container !=null){
        synchronized(container){
            if(container instanceof Lifecycle){
                ((Lifecycle)container).stop();
            }
        }
    }
    //notify
    lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT,null);
}

相关文章推荐

sap start stop process

  • 2011年03月17日 11:28
  • 884KB
  • 下载

MFC环境下Start&Pause&Stop操作(续):尽快结束任务

如何提高用户体验。

start-stop-daemon

  • 2017年01月11日 11:10
  • 30KB
  • 下载

Oracle 11g Data Guard: How to start and stop Redo Apply

1 Starting Redo Apply   To start apply services on a physical standby database, ensure thephysical...

用start-stop-daemon启动Nginx

用start-stop-daemon启动Nginx在前面学习Ubuntu apt-get install nginx 创建的nginx启动脚本中,看到start-stop-daemon的用法。迅速查了...
  • liwf616
  • liwf616
  • 2016年06月25日 11:54
  • 893

shell bash script to start and stop named services

#!/bin/bash function docmd() { #echo 'func',"$1","$2" if [ "$1" = "nginx" ]; then ...

Thread 的stop方法过时Thread already start解决方法

1.Thread 的Stop方法过时为什么不推荐使用Thread.stop?因为它本来就是不安全的。停止线程会使其解锁所有已锁定的显示器。 (当ThreadDeath异常传播到堆栈时,监视器被解锁。)...

自己实现线程的start、suspend、resume、stop方法

在java中使用线程很简单,只需要继承类Thread或者实现接口Runnable 即可。但是如果我们要使用线程挂起、恢复、停止的功能,如果直接使用Thread的suspend、resume、stop方...

man start-stop-daemon

用man start-stop-daemon 这个程序用来启动和关闭系统级别的进程。 下面我用该命令启动我自己编译的nginx程序: start-stop-daemon --start -...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:知识库--StandardService + Lifecycle(start/stop)+initialize(72)
举报原因:
原因补充:

(最多只允许输入30个字)