简体   繁体   English

保持Java程序不带标准运行

[英]Keep Java Program Running Without Standard In

What I would like to accomplish is to start a Java program and have it keep running until the user kills it with a control-C. 我要完成的工作是启动一个Java程序并使其继续运行,直到用户用Control-C杀死它为止。 I realize that it is possible to do this by creating a BufferedReader and having it endlessly loop while reading the BufferedReader, but what I am doing involves me backgrounding the Java program (eg, java -jar app.jar &) which kills standard in so that method would not work. 我意识到,可以通过创建BufferedReader并使其在读取BufferedReader时不断循环来实现此目的,但是我正在做的事情涉及将Java程序(例如java -jar app.jar&)背景化,这会破坏标准。该方法不起作用。 I've read a bit on Java's daemon threads, but I also do not think that is the correct solution in this instance because I want the JVM to stay alive. 我已经阅读了一些有关Java守护程序线程的信息,但是在这种情况下,我也不认为这是正确的解决方案,因为我希望JVM保持活动状态。

Any help would be much appreciated. 任何帮助将非常感激。

Thanks, Chris 谢谢克里斯

I'm guessing you're launching the java program from a different process perhaps? 我猜想您是从其他进程启动Java程序吗? A potential option may be integrating the Java Service Wrapper ? 一个潜在的选择可能是集成Java Service Wrapper Depending on what you are doing, licensing may be an issue, and you probably wouldn't kill the process with a ctrl-c, but it's a thought (in addition to the others given above). 根据您的工作,许可可能是一个问题,您可能不会使用ctrl-c终止该过程,但这是一个想法(除了上面给出的其他想法之外)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM