Auto commit

上级 5b0ce43e
class Main { import java.util.LinkedList;
public static void main(String[] args) { import java.util.List;
System.out.println("Hello world!"); import java.util.concurrent.CopyOnWriteArrayList;
} import java.util.concurrent.Semaphore;
public class Main {
private static final List<Integer> productCodeDetailsList = new CopyOnWriteArrayList<>();
private static final Semaphore semaphore = new Semaphore(1);
public static void main(String[] args) {
for (int i = 0; i < 1000; i++) {
int finalI = i;
new Thread(() -> {
try {
semaphore.acquire();
productCodeDetailsList.add(finalI);
if (finalI % 100 == 0) {
productCodeDetailsList.clear();
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
semaphore.release();
}
}).start();
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(productCodeDetailsList);
System.out.println(productCodeDetailsList.size());
}
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册