InstanceProfileCredentialsProvider: use daemon thread for refresh.
When refreshCredentialsAsync is specified, a scheduled executor
is used to refresh credentials, however that executor is not configured
to use daemon threads. As result, that non-daemon thread blocks JVM
exit. This change explicit make the thread into daemon.
@@ -108,7 +108,13 @@ public class InstanceProfileCredentialsProvider implements AWSCredentialsProvide
if (!SDKGlobalConfiguration.isEc2MetadataDisabled()) {
if (refreshCredentialsAsync) {
- executor = Executors.newScheduledThreadPool(1);
+ executor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
+ public Thread newThread(Runnable r) {
+ Thread t = Executors.defaultThreadFactory().newThread(r);
+ t.setDaemon(true);
+ return t;
+ }
+ });
executor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
