提交 cc2e6b30 编写于 作者: S shuang.kou

[v2.0]refractor create a threadpool util

上级 df21fdea
......@@ -8,10 +8,10 @@
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="rpc-framework-core" />
<module name="hello-service-api" />
<module name="example-server" />
<module name="rpc-framework-simple" />
<module name="example-client" />
<module name="hello-service-api" />
<module name="rpc-framework-common" />
</profile>
</annotationProcessing>
......
U java:S106"9Replace this use of System.out or System.err by a logger.(߫ź8.
\ No newline at end of file
U java:S106"9Replace this use of System.out or System.err by a logger.(߫ź8.
[
java:S1854">Remove this useless assignment to local variable "rpcClient2".(8իؤ.
L
java:S1481"/Remove this unused "rpcClient2" local variable.(8ؤ.
\ No newline at end of file
G
java:S1948",Make "parameters" transient or serializable.(
\ No newline at end of file
java:S1948",Make "parameters" transient or serializable.(
\ No newline at end of file
C
java:S1948"&Make "data" transient or serializable.(ݵ8ε .
\ No newline at end of file
java:S1948%"&Make "data" transient or serializable.(ݵ8ε .
\ No newline at end of file
......@@ -43,18 +43,42 @@ Xrpc-framework-common/src/main/java/github/javaguide/enumeration/RpcErrorMessage
README.md,8/e/8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d

Qrpc-framework-simple/src/main/java/github/javaguide/registry/ServiceRegistry.java,4/e/4eee7bde8d258a3ad13d5aad4b1fd0f47f159c22

brpc-framework-simple/src/main/java/github/javaguide/remoting/socket/RpcRequestHandlerRunnable.java,3/8/38c46e918cbf2fd183a4d20b5269ff145a5da008

Xrpc-framework-simple/src/main/java/github/javaguide/registry/DefaultServiceRegistry.java,8/a/8a8f0ad1908e89647431f04ae22e059fd159d0c1

Rrpc-framework-simple/src/main/java/github/javaguide/remoting/socket/RpcClient.java,8/c/8c93c859db3a1cebbda725b6225a89337732c108

Wrpc-framework-simple/src/main/java/github/javaguide/remoting/socket/RpcClientProxy.java,3/5/350655342260f50b6ee7ce69dcb361bad3956984

Rrpc-framework-simple/src/main/java/github/javaguide/remoting/socket/RpcServer.java,c/f/cf4f29284214a49bc9f1eeb91eff2d0fbb46e184

Srpc-framework-simple/src/main/java/github/javaguide/remoting/RpcRequestHandler.java,e/b/eb77dbc7968406e86bad5a749c9941052f4f3ccc
:
.gitignore,a/5/a5cc2925ca8258af241be7e5b0381edf30266302
\ No newline at end of file
.gitignore,a/5/a5cc2925ca8258af241be7e5b0381edf30266302

Yrpc-framework-simple/src/main/java/github/javaguide/transport/socket/SocketRpcServer.java,4/f/4f3eda1b64c4d4f1b976343bec03d82d70d85cb1

Yrpc-framework-simple/src/main/java/github/javaguide/transport/netty/NettyKryoDecoder.java,7/9/79a691ec739a58083ef0ac1389203a2fbd71f456
}
Mrpc-framework-simple/src/main/java/github/javaguide/serialize/Serializer.java,a/2/a281e49e82a8ec2f7ba12a8bcb5f2186f46d0c77

Urpc-framework-common/src/main/java/github/javaguide/exception/SerializeException.java,1/e/1e9d139dec5a90552b914b239037df398d72bfb1

Vrpc-framework-simple/src/main/java/github/javaguide/serialize/kyro/KryoSerializer.java,7/7/77bd9277dc37adef29330c1e78ac2f2485032917

Qrpc-framework-simple/src/main/java/github/javaguide/transport/RpcClientProxy.java,2/8/28a849b18f6cfe08ef45a480dff1b8324e54e765
|
Lrpc-framework-simple/src/main/java/github/javaguide/transport/RpcClient.java,a/2/a2293a8598601b418206102ff4a42e86ac5c116d

Yrpc-framework-simple/src/main/java/github/javaguide/transport/socket/SocketRpcClient.java,5/0/50091113d4118fd9d05b7a80930d905591dadd6c

Yrpc-framework-simple/src/main/java/github/javaguide/transport/netty/NettyKryoEncoder.java,e/5/e5d48526802e06de10a1802186f9d33d10ff47aa
r
Bexample-server/src/main/java/github/javaguide/NettyServerMain.java,1/7/171870430a59c0c44d9340650aff70ba39acaea8
r
Bexample-client/src/main/java/github/javaguide/NettyClientMain.java,9/e/9ec852e88ae42cd2b9eceb76fd0df53f26fa5b76

Wrpc-framework-simple/src/main/java/github/javaguide/transport/netty/NettyRpcClient.java,a/2/a2710f8ba941b11e1d834a0c57a10db363ee4baf

Wrpc-framework-simple/src/main/java/github/javaguide/transport/netty/NettyRpcServer.java,b/a/ba3e575560636fde885135fa5277f533bf61af1c

[rpc-framework-simple/src/main/java/github/javaguide/transport/netty/NettyClientHandler.java,c/d/cd2bc58a2ed26406a5749d14c0148f8237bb9e14

Trpc-framework-simple/src/main/java/github/javaguide/transport/RpcRequestHandler.java,7/6/76847b5dee1f00ac9229b826500369c60abd7b74

irpc-framework-simple/src/main/java/github/javaguide/transport/socket/SocketRpcRequestHandlerRunnable.java,7/d/7dc3255c598b3c45cab343a0a79f2aab582ce3a0

[rpc-framework-simple/src/main/java/github/javaguide/transport/netty/NettyServerHandler.java,9/a/9a59d8568dc116ae0a68f1173ac9ae7c57ee637e
\ No newline at end of file
......@@ -2,8 +2,7 @@ package github.javaguide;
import github.javaguide.transport.RpcClient;
import github.javaguide.transport.RpcClientProxy;
import github.javaguide.transport.netty.NettyRpcClient;
import github.javaguide.transport.socket.SocketRpcClient;
import github.javaguide.transport.netty.client.NettyRpcClient;
/**
* @author shuang.kou
......
......@@ -2,7 +2,7 @@ package github.javaguide;
import github.javaguide.transport.RpcClient;
import github.javaguide.transport.RpcClientProxy;
import github.javaguide.transport.netty.NettyRpcClient;
import github.javaguide.transport.netty.client.NettyRpcClient;
import github.javaguide.transport.socket.SocketRpcClient;
/**
......
package github.javaguide;
import github.javaguide.registry.DefaultServiceRegistry;
import github.javaguide.transport.netty.NettyRpcServer;
import github.javaguide.transport.socket.SocketRpcServer;
import github.javaguide.transport.netty.server.NettyRpcServer;
/**
* @author shuang.kou
......
......@@ -15,8 +15,11 @@
<!--logging-->
<log4j.version>2.9.0</log4j.version>
<slf4j.version>1.7.25</slf4j.version>
<!--Netty-->
<netty.version>4.1.42.Final</netty.version>
<kryo.version>4.0.2</kryo.version>
<!--tools-->
<guava.version>29.0-jre</guava.version>
</properties>
<modules>
<module>rpc-framework-core</module>
......
......@@ -11,5 +11,13 @@
<artifactId>rpc-framework-common</artifactId>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
</project>
package github.javaguide.utils.concurrent;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* 创建 ThreadPool(线程池) 的工具类.
*
* @author shuang.kou
* @createTime 2020年05月26日 16:00:00
*/
public class ThreadPoolFactory {
/**
* 线程池参数
*/
private static final int CORE_POOL_SIZE = 10;
private static final int MAXIMUM_POOL_SIZE_SIZE = 100;
private static final int KEEP_ALIVE_TIME = 1;
private static final int BLOCKING_QUEUE_CAPACITY = 100;
private ThreadPoolFactory() {
}
public static ExecutorService createDefaultThreadPool(String threadNamePrefix) {
return createDefaultThreadPool(threadNamePrefix, false);
}
public static ExecutorService createDefaultThreadPool(String threadNamePrefix, Boolean daemon) {
// 使用有界队列
BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(BLOCKING_QUEUE_CAPACITY);
ThreadFactory threadFactory = createThreadFactory(threadNamePrefix, daemon);
return new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE_SIZE, KEEP_ALIVE_TIME, TimeUnit.MINUTES, workQueue, threadFactory);
}
/**
* 创建 ThreadFactory 。如果threadNamePrefix不为空则使用自建ThreadFactory,否则使用defaultThreadFactory
*
* @param threadNamePrefix 作为创建的线程名字的前缀
* @param daemon 指定是否为 Daemon Thread(守护线程)
* @return ThreadFactory
*/
private static ThreadFactory createThreadFactory(String threadNamePrefix, Boolean daemon) {
if (threadNamePrefix != null) {
if (daemon != null) {
return new ThreadFactoryBuilder().setNameFormat(threadNamePrefix + "-%d").setDaemon(daemon).build();
} else {
return new ThreadFactoryBuilder().setNameFormat(threadNamePrefix + "-%d").build();
}
}
return Executors.defaultThreadFactory();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册