The code you see below tries to achieve the following:
... etc. without end.
So the conclusion I expect is simple:
line 0
line 1
..
..
However, I get a random number of "lines i", where I am also random. Here's an example output:
Line 0
Line 38919
Line 47726
Line 54271
, , , "hold" true false, .
import java.util.*;
public class Test {
static boolean held = true;
static ArrayList<String> line = new ArrayList<>();
public static void main(String[] args) {
new Thread() {
@Override
public void run() {
int i = 0;
while(true) {
if(held) {
line.add("Line " + i);
i++;
held = false;
}
}
}
}.start();
while(true) {
if(!held) {
System.out.println( line.get(line.size() - 1) );
line.remove(line.size() - 1);
held = true;
}else continue;
}
}
}