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.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|
@ -305,7 +304,9 @@ public final class GrpcUtil {
|
||||||
@Override
|
@Override
|
||||||
public ExecutorService create() {
|
public ExecutorService create() {
|
||||||
return Executors.newCachedThreadPool(new ThreadFactoryBuilder()
|
return Executors.newCachedThreadPool(new ThreadFactoryBuilder()
|
||||||
.setNameFormat(name + "-%d").build());
|
.setDaemon(true)
|
||||||
|
.setNameFormat(name + "-%d")
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -326,14 +327,10 @@ public final class GrpcUtil {
|
||||||
new Resource<ScheduledExecutorService>() {
|
new Resource<ScheduledExecutorService>() {
|
||||||
@Override
|
@Override
|
||||||
public ScheduledExecutorService create() {
|
public ScheduledExecutorService create() {
|
||||||
return Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
return Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
|
||||||
@Override
|
.setDaemon(true)
|
||||||
public Thread newThread(Runnable r) {
|
.setNameFormat("grpc-timer-%d")
|
||||||
Thread thread = new Thread(r);
|
.build());
|
||||||
thread.setDaemon(true);
|
|
||||||
return thread;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,12 @@
|
||||||
package io.grpc.internal;
|
package io.grpc.internal;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
|
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.annotation.concurrent.ThreadSafe;
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
@ -65,13 +65,10 @@ public final class SharedResourceHolder {
|
||||||
new ScheduledExecutorFactory() {
|
new ScheduledExecutorFactory() {
|
||||||
@Override
|
@Override
|
||||||
public ScheduledExecutorService createScheduledExecutor() {
|
public ScheduledExecutorService createScheduledExecutor() {
|
||||||
return Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
return Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
|
||||||
@Override public Thread newThread(Runnable r) {
|
.setDaemon(true)
|
||||||
Thread thread = new Thread(r);
|
.setNameFormat("grpc-shared-destroyer-%d")
|
||||||
thread.setDaemon(true);
|
.build());
|
||||||
return thread;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue