Skip to content
This repository has been archived by the owner on Jul 5, 2021. It is now read-only.

Commit

Permalink
Fixes #60. Stop progress printing thread after upload
Browse files Browse the repository at this point in the history
This is not the most elegant solution, but it does stop the progress printer
after the upload is done.
  • Loading branch information
MoriTanosuke committed Dec 17, 2017
1 parent 6889a44 commit a358301
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
import java.math.MathContext;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class UploadArchiveCommand extends AbstractCommand {

public static final ScheduledExecutorService SCHEDULED_POOL = Executors.newScheduledThreadPool(1);
public static final int PROGRESS_PRINT_PERIOD = 5;
private final ArchiveTransferManager atm;

Expand Down Expand Up @@ -79,7 +81,7 @@ private BigDecimal calcPercentage(double x1, double y1) {
return x.divide(y, MathContext.DECIMAL64).multiply(BigDecimal.valueOf(100));
}
};
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(progressPrinter, 3, PROGRESS_PRINT_PERIOD, TimeUnit.SECONDS);
SCHEDULED_POOL.scheduleAtFixedRate(progressPrinter, 3, PROGRESS_PRINT_PERIOD, TimeUnit.SECONDS);
}
final String archiveId = atm.upload(sameAccountId, vaultName, uploadFile.getName(), uploadFile,
progressTracker).getArchiveId();
Expand All @@ -96,6 +98,9 @@ public void exec(OptionSet options, GlacierUploaderOptionParser optionParser) {
for (File uploadFile : files) {
this.upload(vaultName, uploadFile);
}

// stop progress tracker
SCHEDULED_POOL.shutdown();
}

@Override
Expand Down

0 comments on commit a358301

Please sign in to comment.