有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

并行处理如何使用Threadpool并行化大数据的java源代码

我尝试用Java中的ExecutorServiceLinkedList来并行一些源代码

在下面的源代码中,对文本文件的每一行都进行了一些处理

当每一行相对较短时,以下源代码运行良好(读取所有行并完成进程)

然而,当它相对较长时,程序会停止读取一行而不会出现任何错误

有^{的容量吗?我能增加容量吗?还有其他合适的并行化方法吗

        ExecutorService threadPool = Executors.newFixedThreadPool(4);
        Collection<Callable<Void>> processes = new LinkedList<Callable<Void>>();

        int c = 0;
        while ((string = br.readLine()) != null) {
            final String str = string;
            processes.add(new Callable<Void>() {
                @Override
                public Void call() {
                    // some process
                    return null;
                }
            });
        }

        try {
            threadPool.invokeAll(processes);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } finally {
            System.out.println("parallel finishes");
            threadPool.shutdown();
        }

共 (0) 个答案