Source:
public void send(File file) { log.debug("send file: {}", file.getPath()); AtomicInteger tasksSubmitted = new AtomicInteger(); ExecutorService executor = Executors.newFixedThreadPool(nThreads); ImmutableList.Builder<Future<Part>> results = ImmutableList.builder(); progress.start(); for (final Part part : parts) { tasksSubmitted.incrementAndGet(); try (FileInputStream fis = new FileInputStream(file)) { final MappedByteBuffer buffer = fis.getChannel().map(FileChannel.MapMode.READ_ONLY, part.getOffset(), part.getPartSize()); buffer.load(); log.debug("Pausing before creating new Callable task"); TimeUnit.SECONDS.sleep(3); log.debug("Submitting new Callable task"); results.add(executor.submit(new Callable<Part>() { @Override public Part call() throws Exception { try { DataChannel channel = new ProgressDataChannel(new MemoryMappedDataChannel(buffer, 0, part.getPartSize(), null), progress); if (part.isCompleted()) { log.debug("Checksumming part: {}", part); if (checksum && isCorrupted(channel, part, file)) { log.debug("Fail checksum. Reupload part: {}", part); progress.startTransfer(); proxy.uploadPart(channel, part, objectId, uploadId); } progress.incrementChecksumParts(); } else { progress.startTransfer(); proxy.uploadPart(channel, part, objectId, uploadId); progress.incrementParts(1); } } finally { memory.addAndGet(part.getPartSize()); tasksSubmitted.decrementAndGet(); } return part; } })); } long remaining = memory.addAndGet(-part.getPartSize()); log.debug("Remaining Memory : {}", remaining); log.debug("Number of submitted tasks : {}", tasksSubmitted.get()); while (memory.get() < 0L) { log.debug("Memory is low. Wait..."); TimeUnit.MILLISECONDS.sleep(FREE_MEMORY_TIME_DELAY); } } log.debug("thread pool shut down request ..."); executor.shutdown(); executor.awaitTermination(super.maxUploadDuration, TimeUnit.DAYS); log.debug("thread pool shut down request completed."); progress.stop(); try { takeCareOfException(results.build()); proxy.finalizeUpload(objectId, uploadId); } catch (Throwable e) { progress.end(true); throw e; } progress.end(false); }

Target:
public void send(File file) { log.debug("send file: {}", file.getPath()); AtomicInteger tasksSubmitted = new AtomicInteger(); ExecutorService executor = Executors.newFixedThreadPool(nThreads); ImmutableList.Builder<Future<Part>> results = ImmutableList.builder(); progress.start(); for (final Part part : parts) { tasksSubmitted.incrementAndGet(); try (FileInputStream fis = new FileInputStream(file)) { final MappedByteBuffer buffer = fis.getChannel().map(FileChannel.MapMode.READ_ONLY, part.getOffset(), part.getPartSize()); buffer.load(); log.debug("Submitting new Callable task"); results.add(executor.submit(new Callable<Part>() { @Override public Part call() throws Exception { try { DataChannel channel = new ProgressDataChannel(new MemoryMappedDataChannel(buffer, 0, part.getPartSize(), null), progress); if (part.isCompleted()) { log.info("Checksumming part: {}", part); if (checksum && isCorrupted(channel, part, file)) { log.info("Checksum failed; Reuploading part: {}", part); progress.startTransfer(); proxy.uploadPart(channel, part, objectId, uploadId); } progress.incrementChecksumParts(); } else { log.info("Sending remaining part {}", part); progress.startTransfer(); proxy.uploadPart(channel, part, objectId, uploadId); progress.incrementParts(1); } } finally { memory.addAndGet(part.getPartSize()); tasksSubmitted.decrementAndGet(); } return part; } })); } long remaining = memory.addAndGet(-part.getPartSize()); log.debug("Remaining Memory : {}", remaining); log.debug("Number of submitted tasks : {}", tasksSubmitted.get()); while (memory.get() < 0L) { log.debug("Memory is low. Wait..."); TimeUnit.MILLISECONDS.sleep(FREE_MEMORY_TIME_DELAY); } } log.debug("thread pool shut down request ..."); executor.shutdown(); executor.awaitTermination(super.maxUploadDuration, TimeUnit.DAYS); log.debug("thread pool shut down request completed."); progress.stop(); try { takeCareOfException(results.build()); proxy.finalizeUpload(objectId, uploadId); } catch (Throwable e) { progress.end(true); throw e; } progress.end(false); }