java - Java 线程 - 循环内的内容
问题描述
很简单。当我使用这样的方法运行时:
@Override
public void run() {
CraftRoulette.getInstance();
while(socket==null && outputstream==null && inputstream==null) {
System.out.println("ahah");
}
System.out.println("RUN");
while(socket!=null && !socket.isClosed()) {
System.out.println("STOP");
System.out.println("Checking");
checkForUpdatesOnServer();
}
if(socket!=null && socket.isClosed()) System.out.println("FODA-SE, MAS QUE BEM!");
}
它输出:
ahah
(...)
ahah
RUN
STOP
Checking
但是,如果我删除第一个循环的内容:
@Override
public void run() {
CraftRoulette.getInstance();
while(socket==null && outputstream==null && inputstream==null) {
}
System.out.println("RUN");
while(socket!=null && !socket.isClosed()) {
System.out.println("STOP");
System.out.println("Checking");
checkForUpdatesOnServer();
}
if(socket!=null && socket.isClosed()) System.out.println("FODA-SE, MAS QUE BEM!");
}
它不输出任何东西。这是我应用的唯一更改。为什么让 sysout 让 run 方法继续运行而不是直接杀死它?
编辑:插座上的易失性完成了这项工作,谢谢!
解决方案
推荐阅读
- excel - 在值变化时动态运行宏|VBA|Excel|
- biztalk - %MessageID% 与 BTS.MessageID 不同
- c - 如何在arm-none-eabi中编译以__asm开头的C函数?
- android-studio - 升级 AndroidStudio 到 3.4.1 和 gradle 问题
- reactjs - useImperativeHandle 钩子不更新值
- reactjs - 如何在反应中使用渲染道具处理useEffect
- r - 操作包含字符的数据框中的一些数值列
- angular - Angular 7中的嵌套路由,使用模块和延迟加载
- javascript - 更改输入标签中的值后自动模拟输入键
- python - 使用pytest时无法在同一目录中导入模块