Very simple. When I use the method run like this:
@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!");
}
it outputs:
ahah
(...)
ahah
RUN
STOP
Checking
However, if I remove the content of the first cycle:
@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!");
}
It doesn't output anything. That's the only change I apply. Why does having the sysout keep the run method going and not having just kills it?
EDIT: Volatile on the socket did the job, thank you!