非常简单。当我使用这种方法运行时:
@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方法继续运行,而不仅仅是杀死它呢?
编辑:套接字上的挥发性已完成工作,谢谢!