How to stop infinite loop in JShell / Kulla?

女生的网名这么多〃 提交于 2020-01-04 04:22:07

问题


JShell is a Java REPL that is scheduled to be released alongside Java 9; however, there is an open beta for it.

If I create an infinite loop in JShell (Project Kulla) by typing:

-> while(true) {}

JShell will loop forever. Short of completely quitting JShell, is there a way to stop an individual line of code while it's running in JShell (after you have already begun evaluation of the code)?


回答1:


Actually there is a way. Just hit CTRL + c:

-> while(true) {}
Killed.

-> 

It'll kill the loop and will not exit the shell.

Note that it'll take ~1-2 seconds for the kill process to finish, if you hit it twice it'll kill the statement and then will exit the shell.

I'm using JDK 9 EA build 107 on 03-01-2016 (#4560)



来源:https://stackoverflow.com/questions/35759212/how-to-stop-infinite-loop-in-jshell-kulla

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!