I've noticed this bug (if it is a bug) and decided to make a test environment. Does anyone know if this is an actual problem or is it just me?
import java.util.Random;
public class Start {
public static boolean value;
public static void main(String[] args){
Thread thread = new Thread(){
@Override
public void run(){
random();
}
};
thread.start();
while(true){
if(value) System.out.println("Done");
}
}
public static void random(){
while(true){
value = new Random().nextInt(5) == 0;
}
}
}
I would expect this code to be spamming out "Done"s, but instead I get a bunch at the beginning and then no additions. When I modify the code as so:
while(true){
System.out.print(""); //Modification
if(value) System.out.println("Done");
}
It starts spamming the "Done"s. Anyone know what's up? NOTE: I have tested this in an Eclipse environment and a compiled jar while using jdk 1.8.0 v.25 and jre 1.8.0 v.51.