【问题标题】:Parallelize sequential upload using multiple threads into s3?使用多个线程将顺序上传并行化到 s3?
【发布时间】:2012-12-24 18:51:12
【问题描述】:

同时,我正在将多个文件上传到 s3,如下所示:

public void put(String path, final BufferedImage ... images) {


        for(int i = 0; i < images.length; i++) {
            final BufferedImage image = images[i];
            fileMapper.write(NAMESPACE, new String[] { path, Integer.toString(i) + ".png" }, new FileMapper.Writer() {
                @Override
                public void write(OutputStream out) throws IOException {
                    ImageIO.write(image, "png", out);
                }
            });
        }
    } 

我想通过使用多个线程(同时多张图片)上传它。有人可以帮助我并指导我该怎么做吗?

【问题讨论】:

  • 瓶颈是你的CPU还是网络?即您要优化哪个瓶颈?
  • 您是否尝试将这些作为任务添加到 ExecutorService?
  • 我不是这个领域的专家,所以我没有尝试过。你能指导我怎么做吗

标签: java multithreading amazon-s3


【解决方案1】:

您可以使用 Java 5 中的 Executor Framework 或 Java 7 中的 Fork/join 来做到这一点。

请参考以下链接获取示例。

Executor Framework Example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 2021-04-04
    相关资源
    最近更新 更多