Skip to content

Instantly share code, notes, and snippets.

@pigeon2049
Created May 7, 2020 09:23
Show Gist options
  • Save pigeon2049/31e8e599c2f882e92597ef98fbc79083 to your computer and use it in GitHub Desktop.
Save pigeon2049/31e8e599c2f882e92597ef98fbc79083 to your computer and use it in GitHub Desktop.
public static void main(String[] args) throws InterruptedException {
List<Object> packages=new ArrayList<>();
CountDownLatch countDownLatch=new CountDownLatch(100);
for (int i=0;i<100;i++){
int finalI = i;
new Thread(new Runnable() {
@Override
public void run() {
//do sth
packages.add(finalI);
System.out.println(finalI);
countDownLatch.countDown();
}
}).start();
}
countDownLatch.await();
//包裹全部装箱了 统一派发
packages.forEach(System.out::println);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment