跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] 请教一个 Java 线程池问题,子线程会自己挂掉吗?

发表于

代码逻辑如下:

public void fun() {
        List<Integer> list = new ArrayList<>();
        for(int i = 1; i <= 12345; i++) {
            list.add(i);
        }
        int total = list.size();
        int batchSize = total / 3;
        List<List<Integer>> partition = Lists.partition(list, batchSize);
        for (List<Integer> itemList : partition) {
            executorService.execute(() -> subFun(itemList));
        }
    }

    private void subFun(List<Integer> list) {
        String threadName = Thread.currentThread().getName();
        log.info("子线程{}开始执行。。。", threadName);
        for (Integer i : list) {
            .....
        }
        log.info("子线程{}执行总数:{}", threadName, list.size());
    }

总结就是将数据分为 3 块,并行执行,最终的日志结果是,子线程有 3 个开始执行了,却只有 2 个执行完,日志里没有异常信息,方法里也没有 return 的逻辑,有大佬给点排查思路吗

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.