简体   繁体   English

有没有办法在不使用线程的情况下暂停Java程序?

[英]Is there any way to pause the Java program without using threads?

Is there any way to pause the Java program without using thread? 有没有办法在不使用线程的情况下暂停Java程序? I want to know another way to pause the program without exit program like we use System.exit to exit the system. 我想知道在没有退出程序的情况下暂停程序的另一种方法,比如我们使用System.exit退出系统。 Is there any way to pause,stuck the program the same as System.exit does. 有没有办法暂停,卡住程序与System.exit相同。

When you say pause, it means you want some code lines X to execute first and then code lines Y. 当你说暂停时,这意味着你需要先执行一些代码行X然后再代码行Y.

Between X and Y, you want pause which could be via thread sleep and wait. 在X和Y之间,你想要暂停,这可以通过线程休眠和等待。 Wait would mean notify from another thread. 等待意味着从另一个线程通知。 But you don't want to use threads. 但是你不想使用线程。

Another way would be external trigger via property, whose value would act as a condition in your loop. 另一种方法是通过属性进行外部触发,其值将作为循环中的条件。 The loop will be infinite on initial value of property, and condition will be false the moment you change it. 在属性的初始值上循环将是无限的,并且在您更改它时,条件将为false。

Another way to solve is let first X lines execute and Y would be inside MVC controller, which would be again external trigger via service call. 另一种解决方法是让第一行X行执行,Y将在MVC控制器内部,这将是通过服务调用再次外部触发。 This is possible if it's a web application. 如果它是一个Web应用程序,这是可能的。

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

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