Skip to content

Commit

Permalink
Merge pull request Azure#215 from CodingCat/make_theadpool_daemon
Browse files Browse the repository at this point in the history
[DEV] thread pool in BlobOutputStreamInternal should be daemon
  • Loading branch information
jofriedm-msft authored Sep 8, 2017
2 parents 7c52119 + 7e7f329 commit e097b20
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(true);
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.
*/
Expand Down Expand Up @@ -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<Runnable>());
new LinkedBlockingQueue<Runnable>(),
new BlobOutputStreamThreadFactory());
this.completionService = new ExecutorCompletionService<Void>(this.threadExecutor);
}

Expand Down

0 comments on commit e097b20

Please sign in to comment.