Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.
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 方法