mirror of https://github.com/grpc/grpc-java.git
Daemonize shared threads, and make sure each thread has a name
This commit is contained in:
parent
d6dc790f05
commit
f641e081a0
|
|
@ -48,7 +48,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
|
@ -305,7 +304,9 @@ public final class GrpcUtil {
|
|||
@Override
|
||||
public ExecutorService create() {
|
||||
return Executors.newCachedThreadPool(new ThreadFactoryBuilder()
|
||||
.setNameFormat(name + "-%d").build());
|
||||
.setDaemon(true)
|
||||
.setNameFormat(name + "-%d")
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -326,14 +327,10 @@ public final class GrpcUtil {
|
|||
new Resource<ScheduledExecutorService>() {
|
||||
@Override
|
||||
public ScheduledExecutorService create() {
|
||||
return Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread thread = new Thread(r);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
}
|
||||
});
|
||||
return Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
|
||||
.setDaemon(true)
|
||||
.setNameFormat("grpc-timer-%d")
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@
|
|||
package io.grpc.internal;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
|
@ -65,13 +65,10 @@ public final class SharedResourceHolder {
|
|||
new ScheduledExecutorFactory() {
|
||||
@Override
|
||||
public ScheduledExecutorService createScheduledExecutor() {
|
||||
return Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
||||
@Override public Thread newThread(Runnable r) {
|
||||
Thread thread = new Thread(r);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
}
|
||||
});
|
||||
return Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
|
||||
.setDaemon(true)
|
||||
.setNameFormat("grpc-shared-destroyer-%d")
|
||||
.build());
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue