Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » MobiLink - 服务器管理 » MobiLink 服务器 API » 使用 Java 语言编写同步脚本 » 用于 Java 的 MobiLink 服务器 API 参考

 

ShutdownListener 接口

语法
public ianywhere.ml.script.ShutdownListener
注释

用于捕获服务器关闭的监听器接口。使用此接口可确保在服务器退出前清理所有线程、连接及其它资源。

成员

ianywhere.ml.script.ShutdownListener 的所有成员,包括所有继承的成员。

示例

以下代码为 ServerContext 安装 ShutdownListener。

class MyShutdownListener implements ShutdownListener {
    FileOutputStream _outFile; 
    public MySutdownListener(FileOutputStream outFile) {
        _outFile = outFile;
    }
    
    public void shutdownPerformed(ServerContext sc) {
        // Add shutdown code
        try {
            _outFile.write(("Shutting Down" + "\n").getBytes());
            _outFile.flush();
        }
        catch(Exception e) {
            // Print some error output to the MobiLink log.
            e.printStackTrace();
        }
        // ...
    }
}

以下代码注册 MyShutdownListener。可以从有权访问 ServerContext 的任何位置(例如类构造函数或同步脚本)调用此代码。

// ServerContext serv_context;
// FileOutputStream outFile
serv_context.addShutdownListener(new MyShutdownListener(outFile));

shutdownPerformed 方法