|
27 | 27 | import java.util.HashSet; |
28 | 28 | import java.util.Set; |
29 | 29 | 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; |
37 | 32 |
|
38 | 33 | import com.microsoft.azure.storage.AccessCondition; |
39 | 34 | import com.microsoft.azure.storage.Constants; |
|
51 | 46 | */ |
52 | 47 | final class BlobOutputStreamInternal extends BlobOutputStream { |
53 | 48 |
|
| 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 | + |
54 | 72 | /** |
55 | 73 | * Holds the {@link AccessCondition} object that represents the access conditions for the blob. |
56 | 74 | */ |
@@ -171,9 +189,10 @@ private BlobOutputStreamInternal(final CloudBlob parentBlob, final AccessConditi |
171 | 189 | this.threadExecutor = new ThreadPoolExecutor( |
172 | 190 | this.options.getConcurrentRequestCount(), |
173 | 191 | this.options.getConcurrentRequestCount(), |
174 | | - 10, |
| 192 | + 10, |
175 | 193 | TimeUnit.SECONDS, |
176 | | - new LinkedBlockingQueue<Runnable>()); |
| 194 | + new LinkedBlockingQueue<Runnable>(), |
| 195 | + new BlobOutputStreamThreadFactory()); |
177 | 196 | this.completionService = new ExecutorCompletionService<Void>(this.threadExecutor); |
178 | 197 | } |
179 | 198 |
|
|
0 commit comments