Search code examples
amazon-web-servicesamazon-s3aws-java-sdk

AWS S3 SDK - how do I set thread pool size?


I'm trying to set thread pool size for S3 multipart uploads to control number of parallel uploads being made.

As per this AWS blog page - https://aws.amazon.com/blogs/developer/parallelizing-large-uploads-for-speed-and-reliability/ I need to pass Executors.newFixedThreadPool(n) to TransferManager but I cannot find a way to do the same with TransferManagerBuilder.

We have TransferManagerBuilder.standard().withExecutorFactory() that accepts ExecutyorFactory but it has no implementation.

How can I specify thread pool size using TransferManagerBuilder?


Solution

  • The JavaDoc and GitHub suggest that there is a method TransferManagerBuilder#withExecutorFactory that takes an ExecutorFactory, with an implementation that sets it on the builder.

    Make sure you call the build method on the builder, which should return you an instance of TransferManager.

    final TransferManager tm = TransferManagerBuilder
            .standard()
            .withExecutorFactory(() -> Executors.newFixedThreadPool(numThreads))
            .build();