我想停止运行在端口8080上的服务器。在我的java应用程序中,每当应用程序关闭时,此服务器也需要停止。但我找不到任何解决方案,除了手动停止服务器。有没有办法阻止代码服务器?通过下面 我已经给你的方式,我使用的是Windows 7使用Java代码停止运行服务器?
1
A
回答
1
你是如何启动SymmetricDs的?作为一个Windows服务,作为一个WAR还是嵌入在你的应用程序中?
查看用户指南,似乎如果您可以将它嵌入代码中,您应该能够直接启动和停止它。 user guide中的更多详细信息以及以下示例代码。
import org.jumpmind.symmetric.SymmetricWebServer;
public class StartSymmetricEngine {
/**
* Start an engine that is configured by two properties files. One is
* packaged with the application and contains overridden properties that are
* specific to the application. The other is found in the application's
* working directory. It can be used to setup environment specific
* properties.
*/
public static void main(String[] args) throws Exception {
SymmetricWebServer node = new SymmetricWebServer(
"classpath://my-application.properties");
// this will create the database, sync triggers, start jobs running
node.start(8080);
// this will stop the node
node.stop();
}
}
0
try {
// Execute a command to terminate your server
String command = "command to stop your server";
Process child = Runtime.getRuntime().exec(command);
} catch (IOException e) {
}
0
,因为我没有看到代码,如何创建服务器和接受连接,下面ooptions.you应尽量落实firstway, 其余的选项不能保证是否会导致正确的进程被终止。
-
public void stopServer() { threadReference.interrupt(); } while(!Thread.interrupted()) { // Accept Server Connection try { Thread.sleep(1000); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } } Runtime.getRunTime().addShutDownHook(new Thread() { public void run() { try { ref.stop(); } catch (IOException e) { // close server socket // other clean up e.printStackTrace(); } } });
你需要调用Runtime.getRuntime()TASKKILL/F/IM或者是有JPS哪个更好杀死相关进程注明。
try
{
Process p = Runtime.getRuntime().exec("TASKKILL /F /IM communicator*"); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String result = null; while ((result= in.readLine()) != null) { if ("SUCCESS".equals(result.substring(0,7)) { break; } } } catch (IOException e) { e.printStackTrace(); }
0
你为什么不检查Cargo?它提供了一个Java API来启动/停止Java容器。您可以在主页中找到支持的容器列表。
相关问题
- 1. C代码停止运行
- 2. 停止RMI服务器(JAVA)
- 3. 码头服务器运行php代码
- 4. preg_match_all在服务器上执行停止代码(大文件)
- 5. 服务代码在应用程序停止时停止
- 6. 如何停止作为Windows服务运行的web.py服务器
- 7. 在服务器上运行Python代码
- 8. 如何服务器代码运行MVC2
- 9. 如何使TCP服务器运行直至停止
- 10. 终止一个执行器服务和极快的Java代码?
- 11. 如何停止运行服务?
- 12. 代码在错误后停止运行
- 13. 文件处理:代码停止运行
- 14. 停止,直到代码运行
- 15. 如何停止运行某些代码?
- 16. 的Java停止服务器线程
- 17. 使用命令停止laravel服务器
- 18. 通过java代码启动和停止postgreSQL服务
- 19. Java代码突然停止
- 20. 如何告诉Puppet在停止运行时停止服务?
- 21. 停止运行PHP服务器,命令行
- 22. 服务器运行java servlet
- 23. 运行Java throgh服务器
- 24. 代码(java,多线程)在一行代码后停止执行
- 25. 如何使用AJAX与服务器通信并运行代码?
- 26. 使用ansible停止服务
- 27. 当我从服务器运行Web服务时,java代码中的空日期
- 28. 循环停止运行java
- 29. 每24小时运行一次服务,并在5次后停止android代码
- 30. 代码没有发挥好[错误:服务器停止响应]
是否例如一个Apache服务器,还是你自己开发的服务器?如果这样的话,这种方式将会完全不同。 – 2011-02-15 10:16:01
它是一个独立的Java应用程序或基于Web? – 2011-02-15 10:18:10
你可以在这里发布你的代码吗? – 2011-02-15 10:24:38