|
30 | 30 | import com.google.cloud.storage.StorageException;
|
31 | 31 | import com.google.cloud.storage.StorageOptions;
|
32 | 32 | import com.google.common.base.Strings;
|
| 33 | +import com.google.common.util.concurrent.ThreadFactoryBuilder; |
33 | 34 | import java.io.IOException;
|
34 | 35 | import java.io.InputStream;
|
35 | 36 | import java.time.Duration;
|
|
41 | 42 | import java.util.concurrent.ExecutorService;
|
42 | 43 | import java.util.concurrent.Executors;
|
43 | 44 | import java.util.concurrent.Future;
|
| 45 | +import java.util.concurrent.ThreadFactory; |
44 | 46 | import java.util.concurrent.TimeUnit;
|
45 | 47 | import java.util.concurrent.TimeoutException;
|
46 | 48 | import java.util.logging.Level;
|
@@ -153,11 +155,14 @@ public static Boolean forceDelete(Storage storage, String bucket, long timeout,
|
153 | 155 | public static Boolean forceDelete(
|
154 | 156 | Storage storage, String bucket, long timeout, TimeUnit unit, String userProject)
|
155 | 157 | throws InterruptedException, ExecutionException {
|
156 |
| - ExecutorService executor = Executors.newSingleThreadExecutor(); |
| 158 | + ThreadFactory threadFactory = |
| 159 | + new ThreadFactoryBuilder().setDaemon(true).setNameFormat("forceDelete-%s").build(); |
| 160 | + ExecutorService executor = Executors.newSingleThreadExecutor(threadFactory); |
157 | 161 | Future<Boolean> future = executor.submit(new DeleteBucketTask(storage, bucket, userProject));
|
158 | 162 | try {
|
159 | 163 | return future.get(timeout, unit);
|
160 | 164 | } catch (TimeoutException ex) {
|
| 165 | + future.cancel(true); |
161 | 166 | return false;
|
162 | 167 | } finally {
|
163 | 168 | executor.shutdown();
|
|
0 commit comments