【问题标题】:java shutdown hook "system cannot find message text"java关闭挂钩“系统找不到消息文本”
【发布时间】:2013-11-29 03:26:28
【问题描述】:

我的 Server 类的 main 方法中有以下关闭挂钩:

Runtime.getRuntime().addShutdownHook(new Thread() {
    public void run() {
        if (open) {
            open = false;

            //log out all players
            System.out.println("Logging out all players...");
            Iterator playerIterator = playerList.values().iterator();
            while (playerIterator.hasNext()) {
                Player p = (Player) playerIterator.next();
                playerIterator.remove();
                p.logout("The server has been shut down.");
            }

            //save the World
            System.out.println("Saving world...");
            try {
                String worldFile = Server.path.concat("/worlds/"+worldName);
                ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(worldFile));
                out.writeObject(world);
            } catch (FileNotFoundException fe) {
                System.out.println("World \"" + worldName + "\" couldn't be saved properly - world file not found.");
                fe.printStackTrace();
            } catch (IOException ioe) {
                System.out.println("I/O error while attempting to save world \"" + worldName + "\".");
                ioe.printStackTrace();
            }

            //close Server socket
            try {
                serverSocket.close();
                System.out.println(worldName + " is now closed.");
            } catch (IOException ioe) {
                System.out.println("Failed to close ServerSocket.");
                ioe.printStackTrace();
            }
        }
    }
});

当我停止服务器(通过按 Ctrl+c)时,关闭挂钩会完成它应该做的所有事情(它工作得很好),但是我收到以下消息并且服务器不会完成关闭(我必须再次按 Ctrl+c):

系统找不到消息号 0x237b 的消息文本 应用程序的消息文件。

在我更新到 Java 7 之前,我不认为它曾经这样做过!任何想法为什么它可能会这样做?

【问题讨论】:

  • 你从哪里得到消息?
  • 似乎是 Win7 问题:link
  • @AjayGeorge 谢谢!

标签: java shutdown-hook


【解决方案1】:

http://social.technet.microsoft.com/Forums/windows/en-US/2d506b96-e856-4752-90af-4f8194bb0040/windows-7-command-prompt-message-errors-cmdexe?forum=w7itprogeneral找到答案

您收到这些消息是因为您正在运行 CMD.exe 与 %COMSPEC% 环境中定义的文件夹不同的文件夹 变量。

如果要打开特定文件夹的命令提示符 您可以右键单击并选择“在此处打开命令窗口”(内置 维斯塔和 7)。它非常光滑,因为如果您在网络共享上执行此操作 Windows 会自动为您映射一个驱动器号。 右键单击计算机上的文件夹 C:\windows\system32,同时 按住 shift 键。您会看到一个额外的上下文相关菜单 那里的项目:在此处打开命令提示符。只需单击此菜单,然后 命令窗口将打开,当前工作目录设置为 文件夹的实际位置。

另一种选择是创建一个新的 CMD 快捷方式。

创建一个新的快捷方式,输入 %COMSPEC% 作为目标,然后给出 这是一个你想要的名字。创建后,编辑快捷方式并更改 您希望打开命令提示符的“开始”路径。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多