I have written a Thread that is dedicated to take a screenshot and convert it to jpg. So my other thread can send this screenshot parallel to another computer while the next screenshot is being taken. So far so good. It did not work to take new screenshots until I added a System.out.println... screenshot_ready... That is really weird because a println should not affect the thread.
Can you maybe explain why it only works with this system.out.println?
public void run(){
while(continueLoop){
System.out.println("screenshot_ready: " + screenshot_ready + "\n");
if(!screenshot_ready){
try {
temp = getImageAsJPEG(robot.createScreenCapture(rectangle));
screenshot_ready = true;
System.out.println("screenshot created");
} catch (ImageFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public byte[] returnJPG() {
screenshot_ready = false;
return temp;
}