java 当应用程序正在运行并且 GUI 被隐藏时,然后再次启动同一个应用程序,注意到这一点并告诉已经正在运行的应用程序显示 GUI

发布于 2024-12-17 12:38:14 字数 248 浏览 4 评论 0原文

我想要的只是在已经启动的应用程序上显示 GUI。我有 file.lock 单实例样式应用程序。我想要一些轻量级的东西,而不是 IPC 或 javaspace。

正在考虑使用 Server.accept() 来 ping 已启动的应用程序并使其执行 setVisible(true) 但如果端口正在使用,这可能会导致麻烦。如果第一个端口被占用,可以设置一个端口号表/算法来遵循,但这又是一个坏主意。

您认为,还有哪些替代方案?

All I want is to show the GUI on the already started app. I have file.lock in place singleinstance style app. I want something lightweight not IPC or javaspace.

Was thinking to have a Server.accept() to ping the already started app and make it do setVisible(true) But that would probable lead to trouble if port is in use. One could set up a port number table/algorithm to follow if first port is taken but then again its a bad idea.

What you think, what are the alternatives?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁以何悠 2024-12-24 12:38:14

在端口上监听可能是最好的方法——至少是最可靠的方法。另一种选择是写出一个文件并查找它,但是当您的计算机崩溃并且文件未被删除时,这会导致问题。

如果您无法绑定到该端口,则仅此一项就可能表明服务器正在运行。

如果您希望能够恢复,请发送一条消息并期望在端口上返回特定响应。如果您无法绑定到端口并且没有从端口获得响应,那么可能不是您,因此请通过“此应用程序是否已在运行”对话框提示用户。

Listening on a port is probably the best way--at least the most reliable one. Another option is writing out a file and looking for it but that leads to problems when your computer crashes and the file isn't deleted.

If you can't bind to the port, that alone might be an indication that a server is running.

If you wanted the ability to recover, send a message and expect a specific response back on the port. If you can't bind to the port and don't get a response from the port then it might not be you, so prompt the user with an "Is this app already running" dialog.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文