use of java.util.concurrent.ForkJoinWorkerThread in project grpc-java by grpc.
the class AsyncServer method newServer.
static Server newServer(ServerConfiguration config) throws IOException {
SslContext sslContext = null;
if (config.tls) {
System.out.println("Using fake CA for TLS certificate.\n" + "Run the Java client with --tls --testca");
File cert = TestUtils.loadCert("server1.pem");
File key = TestUtils.loadCert("server1.key");
SslContextBuilder sslContextBuilder = GrpcSslContexts.forServer(cert, key);
if (config.transport == ServerConfiguration.Transport.NETTY_NIO) {
sslContextBuilder = GrpcSslContexts.configure(sslContextBuilder, SslProvider.JDK);
} else {
// Native transport with OpenSSL
sslContextBuilder = GrpcSslContexts.configure(sslContextBuilder, SslProvider.OPENSSL);
}
if (config.useDefaultCiphers) {
sslContextBuilder.ciphers(null);
}
sslContext = sslContextBuilder.build();
}
final EventLoopGroup boss;
final EventLoopGroup worker;
final Class<? extends ServerChannel> channelType;
switch(config.transport) {
case NETTY_NIO:
{
boss = new NioEventLoopGroup();
worker = new NioEventLoopGroup();
channelType = NioServerSocketChannel.class;
break;
}
case NETTY_EPOLL:
{
try {
// These classes are only available on linux.
Class<?> groupClass = Class.forName("io.netty.channel.epoll.EpollEventLoopGroup");
@SuppressWarnings("unchecked") Class<? extends ServerChannel> channelClass = (Class<? extends ServerChannel>) Class.forName("io.netty.channel.epoll.EpollServerSocketChannel");
boss = (EventLoopGroup) groupClass.getConstructor().newInstance();
worker = (EventLoopGroup) groupClass.getConstructor().newInstance();
channelType = channelClass;
break;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
case NETTY_UNIX_DOMAIN_SOCKET:
{
try {
// These classes are only available on linux.
Class<?> groupClass = Class.forName("io.netty.channel.epoll.EpollEventLoopGroup");
@SuppressWarnings("unchecked") Class<? extends ServerChannel> channelClass = (Class<? extends ServerChannel>) Class.forName("io.netty.channel.epoll.EpollServerDomainSocketChannel");
boss = (EventLoopGroup) groupClass.getConstructor().newInstance();
worker = (EventLoopGroup) groupClass.getConstructor().newInstance();
channelType = channelClass;
break;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
default:
{
// Should never get here.
throw new IllegalArgumentException("Unsupported transport: " + config.transport);
}
}
NettyServerBuilder builder = NettyServerBuilder.forAddress(config.address).bossEventLoopGroup(boss).workerEventLoopGroup(worker).channelType(channelType).addService(new BenchmarkServiceImpl()).sslContext(sslContext).flowControlWindow(config.flowControlWindow);
if (config.directExecutor) {
builder.directExecutor();
} else {
// TODO(carl-mastrangelo): This should not be necessary. I don't know where this should be
// put. Move it somewhere else, or remove it if no longer necessary.
// See: https://github.com/grpc/grpc-java/issues/2119
builder.executor(new ForkJoinPool(Runtime.getRuntime().availableProcessors(), new ForkJoinWorkerThreadFactory() {
final AtomicInteger num = new AtomicInteger();
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
ForkJoinWorkerThread thread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
thread.setDaemon(true);
thread.setName("grpc-server-app-" + "-" + num.getAndIncrement());
return thread;
}
}, UncaughtExceptionHandlers.systemExit(), true));
}
return builder.build();
}
use of java.util.concurrent.ForkJoinWorkerThread in project grpc-java by grpc.
the class Utils method getExecutor.
private static synchronized ExecutorService getExecutor() {
if (clientExecutor == null) {
clientExecutor = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), new ForkJoinWorkerThreadFactory() {
final AtomicInteger num = new AtomicInteger();
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
ForkJoinWorkerThread thread = defaultForkJoinWorkerThreadFactory.newThread(pool);
thread.setDaemon(true);
thread.setName("grpc-client-app-" + "-" + num.getAndIncrement());
return thread;
}
}, UncaughtExceptionHandlers.systemExit(), true);
}
return clientExecutor;
}
use of java.util.concurrent.ForkJoinWorkerThread in project quasar by puniverse.
the class ExtendedForkJoinWorkerFactory method newThread.
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
// ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
ForkJoinWorkerThread thread = createThread(pool);
final String workerNumber = thread.getName().substring(thread.getName().lastIndexOf('-') + 1);
final String newThreadName = "ForkJoinPool-" + name + "-worker-" + workerNumber;
thread.setName(newThreadName);
//thread.setUncaughtExceptionHandler(uncaughtExceptionHandler);
return thread;
}
use of java.util.concurrent.ForkJoinWorkerThread in project intellij-community by JetBrains.
the class IdeaForkJoinWorkerThreadFactory method newThread.
@Override
public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
final int n = setNextBit();
ForkJoinWorkerThread thread = new ForkJoinWorkerThread(pool) {
@Override
protected void onTermination(Throwable exception) {
clearBit(n);
super.onTermination(exception);
}
};
thread.setName("JobScheduler FJ pool " + n + "/" + PARALLELISM);
thread.setPriority(Thread.NORM_PRIORITY - 1);
return thread;
}
Aggregations