From cac8f472cb7e71ee50fceba899e39f7cc3fc52e9 Mon Sep 17 00:00:00 2001 From: CodingCat Date: Mon, 4 Sep 2017 20:45:49 -0700 Subject: [PATCH 1/2] set thread pool as daemon --- .../blob/BlobOutputStreamInternal.java | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java index 44fde57d3f7a1..3f34049735052 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java @@ -27,13 +27,8 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.Future; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicInteger; import com.microsoft.azure.storage.AccessCondition; import com.microsoft.azure.storage.Constants; @@ -51,6 +46,29 @@ */ final class BlobOutputStreamInternal extends BlobOutputStream { + private static class BlobOutputStreamThreadFactory implements ThreadFactory { + private final ThreadGroup group; + private final AtomicInteger threadNumber = new AtomicInteger(1); + private final String namePrefix; + + BlobOutputStreamThreadFactory() { + SecurityManager s = System.getSecurityManager(); + group = (s != null) ? s.getThreadGroup() : + Thread.currentThread().getThreadGroup(); + namePrefix = "azure-storage-bloboutputstream-thread-"; + } + + public Thread newThread(Runnable r) { + Thread t = new Thread(group, r, + namePrefix + threadNumber.getAndIncrement(), + 0); + t.setDaemon(false); + if (t.getPriority() != Thread.NORM_PRIORITY) + t.setPriority(Thread.NORM_PRIORITY); + return t; + } + } + /** * Holds the {@link AccessCondition} object that represents the access conditions for the blob. */ @@ -171,9 +189,10 @@ private BlobOutputStreamInternal(final CloudBlob parentBlob, final AccessConditi this.threadExecutor = new ThreadPoolExecutor( this.options.getConcurrentRequestCount(), this.options.getConcurrentRequestCount(), - 10, + 10, TimeUnit.SECONDS, - new LinkedBlockingQueue()); + new LinkedBlockingQueue(), + new BlobOutputStreamThreadFactory()); this.completionService = new ExecutorCompletionService(this.threadExecutor); } From 7e7f32961deb40ff0d0be842f737ba027e0c46e8 Mon Sep 17 00:00:00 2001 From: CodingCat Date: Mon, 4 Sep 2017 20:58:00 -0700 Subject: [PATCH 2/2] fix typo --- .../microsoft/azure/storage/blob/BlobOutputStreamInternal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java index 3f34049735052..0d3854373d764 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java @@ -62,7 +62,7 @@ public Thread newThread(Runnable r) { Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0); - t.setDaemon(false); + t.setDaemon(true); if (t.getPriority() != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY); return t;