Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 103e53b

Browse files
author
jofriedm-msft
authored
Merge pull request #211 from CodingCat/make_theadpool_daemon
thread pool in BlobOutputStreamInternal should be daemon
2 parents e7abcb5 + 7e7f329 commit 103e53b

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobOutputStreamInternal.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,8 @@
2727
import java.util.HashSet;
2828
import java.util.Set;
2929
import java.util.UUID;
30-
import java.util.concurrent.Callable;
31-
import java.util.concurrent.ConcurrentHashMap;
32-
import java.util.concurrent.ExecutorCompletionService;
33-
import java.util.concurrent.Future;
34-
import java.util.concurrent.LinkedBlockingQueue;
35-
import java.util.concurrent.ThreadPoolExecutor;
36-
import java.util.concurrent.TimeUnit;
30+
import java.util.concurrent.*;
31+
import java.util.concurrent.atomic.AtomicInteger;
3732

3833
import com.microsoft.azure.storage.AccessCondition;
3934
import com.microsoft.azure.storage.Constants;
@@ -51,6 +46,29 @@
5146
*/
5247
final class BlobOutputStreamInternal extends BlobOutputStream {
5348

49+
private static class BlobOutputStreamThreadFactory implements ThreadFactory {
50+
private final ThreadGroup group;
51+
private final AtomicInteger threadNumber = new AtomicInteger(1);
52+
private final String namePrefix;
53+
54+
BlobOutputStreamThreadFactory() {
55+
SecurityManager s = System.getSecurityManager();
56+
group = (s != null) ? s.getThreadGroup() :
57+
Thread.currentThread().getThreadGroup();
58+
namePrefix = "azure-storage-bloboutputstream-thread-";
59+
}
60+
61+
public Thread newThread(Runnable r) {
62+
Thread t = new Thread(group, r,
63+
namePrefix + threadNumber.getAndIncrement(),
64+
0);
65+
t.setDaemon(true);
66+
if (t.getPriority() != Thread.NORM_PRIORITY)
67+
t.setPriority(Thread.NORM_PRIORITY);
68+
return t;
69+
}
70+
}
71+
5472
/**
5573
* Holds the {@link AccessCondition} object that represents the access conditions for the blob.
5674
*/
@@ -171,9 +189,10 @@ private BlobOutputStreamInternal(final CloudBlob parentBlob, final AccessConditi
171189
this.threadExecutor = new ThreadPoolExecutor(
172190
this.options.getConcurrentRequestCount(),
173191
this.options.getConcurrentRequestCount(),
174-
10,
192+
10,
175193
TimeUnit.SECONDS,
176-
new LinkedBlockingQueue<Runnable>());
194+
new LinkedBlockingQueue<Runnable>(),
195+
new BlobOutputStreamThreadFactory());
177196
this.completionService = new ExecutorCompletionService<Void>(this.threadExecutor);
178197
}
179198

0 commit comments

Comments
 (0)