Created
May 7, 2020 09:23
-
-
Save pigeon2049/31e8e599c2f882e92597ef98fbc79083 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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