Skip to content

Commit d8ff530

Browse files
committed
feat: support jdk 17+
1 parent 851ad41 commit d8ff530

File tree

6 files changed

+21
-89
lines changed

6 files changed

+21
-89
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ bin
3737
trpc-selector/trpc-selector-open-polaris/polaris
3838
trpc-registry/trpc-registry-open-polaris/polaris
3939
**/target
40+
deploy.sh
4041

4142
# Codecc
4243
.codecc

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ tRPC-Java has the following features:
3434

3535
JDK 8+, Maven 3.6.3+
3636

37-
If using JDK 9 and above, please set the JVM options as follows:
38-
39-
```shell
40-
--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED
41-
```
42-
4337
### Import dependencies
4438

4539
```pom
@@ -56,7 +50,8 @@ If using JDK 9 and above, please set the JVM options as follows:
5650

5751
It is recommended to use [Tencent Kona JDK FIBER 8](https://github.com/Tencent/TencentKona-8). For
5852
usage examples,
59-
see [coroutine](https://github.com/trpc-group/trpc-java-examples/tree/master/trpc-examples-coroutine)
53+
see [coroutine](https://github.com/trpc-group/trpc-java-examples/tree/master/trpc-coroutine)
54+
6055
<h2 id="2">Related Documentation</h2>
6156

6257
- [Quick start](/docs/en/1.quick_start.md)

README.zh_CN.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ tRPC-Java 具有以下特点:
3333

3434
JDK 8+, Maven 3.6.3+
3535

36-
如果使用 JDK 9及其以上版本,JVM 参数请进行如下设置:
37-
38-
```shell
39-
--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.management/sun.management=ALL-UNNAMED --add-opens java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED
40-
```
41-
4236
### 引入依赖
4337

4438
```pom
@@ -54,7 +48,7 @@ JDK 8+, Maven 3.6.3+
5448
#### 使用协程
5549

5650
推荐使用 [Tencent Kona JDK FIBER 8](https://github.com/Tencent/TencentKona-8)
57-
使用示例见[coroutine](https://github.com/trpc-group/trpc-java-examples/tree/master/trpc-examples-coroutine)
51+
使用示例见[coroutine](https://github.com/trpc-group/trpc-java-examples/tree/master/trpc-coroutine)
5852

5953
<h2 id="2">相关文档</h2>
6054

deploy.sh

Lines changed: 0 additions & 65 deletions
This file was deleted.

trpc-core/src/main/java/com/tencent/trpc/core/management/ThreadPoolMXBeanImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Tencent is pleased to support the open source community by making tRPC available.
33
*
4-
* Copyright (C) 2023 THL A29 Limited, a Tencent company.
4+
* Copyright (C) 2023 THL A29 Limited, a Tencent company.
55
* All rights reserved.
66
*
77
* If you have downloaded a copy of the tRPC source code from Tencent,
@@ -14,8 +14,8 @@
1414
import java.util.Objects;
1515
import java.util.concurrent.ThreadPoolExecutor;
1616
import java.util.concurrent.atomic.AtomicInteger;
17+
import javax.management.MalformedObjectNameException;
1718
import javax.management.ObjectName;
18-
import com.sun.jmx.mbeanserver.Util;
1919

2020
public class ThreadPoolMXBeanImpl implements ThreadPoolMXBean {
2121

@@ -67,7 +67,11 @@ public int getMaximumPoolSize() {
6767

6868
@Override
6969
public ObjectName getObjectName() {
70-
return Util.newObjectName(WORKER_POOL_MXBEAN_DOMAIN_TYPE + ",name=" + objectName);
70+
try {
71+
return new ObjectName(WORKER_POOL_MXBEAN_DOMAIN_TYPE + ",name=" + objectName);
72+
} catch (MalformedObjectNameException e) {
73+
throw new IllegalArgumentException(e);
74+
}
7175
}
7276

7377
}

trpc-core/src/main/java/com/tencent/trpc/core/worker/support/thread/ThreadWorkerPool.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,20 @@ public void init() throws TRpcExtensionException {
100100
Class<?> threadClazz = ReflectionUtils.forName(THREAD_CLASS_NAME);
101101
Method ofVirtualMethod = threadClazz.getDeclaredMethod(OF_VIRTUAL_NAME);
102102
Object virtual = ofVirtualMethod.invoke(threadClazz);
103-
Class<?> virtualClazz = virtual.getClass();
103+
Class<?> virtualClazz = ofVirtualMethod.getReturnType();
104104
Method nameMethod = virtualClazz.getMethod(NAME, String.class, long.class);
105-
nameMethod.setAccessible(true);
106105
nameMethod.invoke(virtual, poolConfig.getNamePrefix(), 1);
107106
if (!poolConfig.isShareSchedule()) {
108-
Method schedulerMethod = virtualClazz.getDeclaredMethod(SCHEDULER_NAME, Executor.class);
109-
schedulerMethod.setAccessible(true);
110-
schedulerMethod.invoke(virtual, Executors.newWorkStealingPool(poolConfig.getFiberParallel()));
107+
try {
108+
Method schedulerMethod = virtualClazz.getDeclaredMethod(SCHEDULER_NAME, Executor.class);
109+
schedulerMethod.setAccessible(true);
110+
schedulerMethod.invoke(virtual, Executors.newWorkStealingPool(poolConfig.getFiberParallel()));
111+
} catch (NoSuchMethodException exception) {
112+
logger.error("Only Tencent Kona JDK FIBER 8+ version support scheduler method, error: ",
113+
exception);
114+
}
111115
}
112-
Method factoryMethod = virtualClazz.getDeclaredMethod(FACTORY_NAME);
113-
factoryMethod.setAccessible(true);
116+
Method factoryMethod = virtualClazz.getMethod(FACTORY_NAME);
114117
threadFactory = (ThreadFactory) factoryMethod.invoke(virtual);
115118
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException exception) {
116119
logger.error("The current JDK version cannot use coroutines, please use OpenJDK 21+ or Tencent "

0 commit comments

Comments
 (0)