今天发现了个奇怪的问题,直接看代码:
package bingfa;
import com.sun.javaws.IconUtil;
import java.util.concurrent.ForkJoinPool;
public class ForeachTest {
private class Node{
private int num;
private Node(int num) {
this.num = num;
}
public int get() {
return num;
}
}
Node[] n1 = {new Node(1),new Node(2),new Node(3),new Node(4),new Node(5),new Node(6),};
Node[] n2 = {new Node(11),new Node(22),new Node(33),new Node(44),new Node(55),new Node(66),};
public void test() throws InterruptedException {
Thread t1 = new Thread(() -> {
for (Node n : n1) {
System.out.println(n.get());
if (n.get() == 3) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}