-
Notifications
You must be signed in to change notification settings - Fork 783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ISSUE #483] Virtual thread compatible #508
Changes from 1 commit
f5f25f5
cc83c79
0d0c160
74f64c6
17a913b
706d887
f05dd26
a85826c
4a93554
4495be0
a729e11
6a1e1a9
3755c8b
db44cd8
0a38447
f4b5804
c791fd2
ebc5e0e
e29ebd4
554f3f1
3dc7ee6
0b18056
4154092
d9b5d4d
119d2e2
7944b9b
33a4214
fe40c63
f449863
c40e854
4027731
2f7a99d
a812aff
a96658e
b4e5dcb
7eaf4ca
15929e1
8457c52
69ec089
84d4d30
21e3b41
d063f36
36dc4c4
36cd88a
64afeae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,7 @@ private Object registerAndReturnCommon(Object bean, String beanName) { | |
} else { | ||
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); | ||
if (!(beanDefinition instanceof AnnotatedBeanDefinition)) { | ||
if (beanDefinition.getBeanClassName().equals("org.dromara.dynamictp.core.support.proxy.VirtualThreadExecutorProxy")) { | ||
if (VirtualThreadExecutorProxy.class.getName().equals("org.dromara.dynamictp.core.support.proxy.VirtualThreadExecutorProxy")) { | ||
return doRegisterAndReturnCommon(bean, beanName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 使用VirtualThreadExecutorProxy.class.getName(),后面维护也简单 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里doRegisterAndReturnCommon调用类似原来的代码最后再调用? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
这个我是想着因为现在配置中心里没有需要动态配置的参数所以就直接以common的登记了。想着到时新增参数后再做重构 |
||
} | ||
return bean; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.PriorityBlockingQueue; | ||
import java.util.concurrent.ThreadFactory; | ||
|
||
import static org.dromara.dynamictp.common.constant.DynamicTpConst.ALLOW_CORE_THREAD_TIMEOUT; | ||
import static org.dromara.dynamictp.common.constant.DynamicTpConst.AWAIT_TERMINATION_SECONDS; | ||
|
@@ -74,7 +75,9 @@ | |
@Slf4j | ||
public class DtpBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar, EnvironmentAware { | ||
|
||
private static final Integer JDK_VERSION_21_OFFSET = 21 - 8; | ||
private static final Integer JRE_VERSION_21 = 21; | ||
|
||
private static final String VIRTUAL_THREAD_EXECUTOR_TYPE = "virtual"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 放在common.constant下比较好 |
||
|
||
private Environment environment; | ||
|
||
|
@@ -104,6 +107,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, B | |
try { | ||
args = buildConstructorArgs(executorTypeClass, e); | ||
} catch (UnsupportedOperationException exception) { | ||
log.warn("DynamicTp virtual thread executor {} register warn: update your JDK version or don't use virtual thread executor!", e.getThreadPoolName()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 日志描述有问题,不一定是虚拟线程的异常 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里加下异常日志 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
BeanRegistrationUtil.register(registry, e.getThreadPoolName(), executorTypeClass, propertyValues, args); | ||
|
@@ -115,15 +119,17 @@ private Map<String, Object> buildPropertyValues(DtpExecutorProps props) { | |
propertyValues.put(THREAD_POOL_NAME, props.getThreadPoolName()); | ||
propertyValues.put(THREAD_POOL_ALIAS_NAME, props.getThreadPoolAliasName()); | ||
|
||
propertyValues.put(ALLOW_CORE_THREAD_TIMEOUT, props.isAllowCoreThreadTimeOut()); | ||
propertyValues.put(WAIT_FOR_TASKS_TO_COMPLETE_ON_SHUTDOWN, props.isWaitForTasksToCompleteOnShutdown()); | ||
propertyValues.put(AWAIT_TERMINATION_SECONDS, props.getAwaitTerminationSeconds()); | ||
propertyValues.put(PRE_START_ALL_CORE_THREADS, props.isPreStartAllCoreThreads()); | ||
propertyValues.put(REJECT_HANDLER_TYPE, props.getRejectedHandlerType()); | ||
propertyValues.put(REJECT_ENHANCED, props.isRejectEnhanced()); | ||
propertyValues.put(RUN_TIMEOUT, props.getRunTimeout()); | ||
propertyValues.put(TRY_INTERRUPT_WHEN_TIMEOUT, props.isTryInterrupt()); | ||
propertyValues.put(QUEUE_TIMEOUT, props.getQueueTimeout()); | ||
if (!props.getExecutorType().equals(VIRTUAL_THREAD_EXECUTOR_TYPE)) { | ||
propertyValues.put(ALLOW_CORE_THREAD_TIMEOUT, props.isAllowCoreThreadTimeOut()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 判断不用加 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个目前虚拟线程的proxy没有这些属性,不加的话会报错 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 采用提前返回的形式吧,看着舒服点代码 |
||
propertyValues.put(WAIT_FOR_TASKS_TO_COMPLETE_ON_SHUTDOWN, props.isWaitForTasksToCompleteOnShutdown()); | ||
propertyValues.put(AWAIT_TERMINATION_SECONDS, props.getAwaitTerminationSeconds()); | ||
propertyValues.put(PRE_START_ALL_CORE_THREADS, props.isPreStartAllCoreThreads()); | ||
propertyValues.put(REJECT_HANDLER_TYPE, props.getRejectedHandlerType()); | ||
propertyValues.put(REJECT_ENHANCED, props.isRejectEnhanced()); | ||
propertyValues.put(RUN_TIMEOUT, props.getRunTimeout()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这些字段虚拟线程也会用到,超时相关是在AwareManager扩展中用到 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
这些字段虚拟线程的proxy目前没有这些属性,如果暴露的话会无法生成实例。要是之后有需要的话再进行添加重构吧 |
||
propertyValues.put(TRY_INTERRUPT_WHEN_TIMEOUT, props.isTryInterrupt()); | ||
propertyValues.put(QUEUE_TIMEOUT, props.getQueueTimeout()); | ||
} | ||
|
||
val notifyItems = mergeAllNotifyItems(props.getNotifyItems()); | ||
propertyValues.put(NOTIFY_ITEMS, notifyItems); | ||
|
@@ -144,13 +150,13 @@ private Object[] buildConstructorArgs(Class<?> clazz, DtpExecutorProps props) th | |
} else if (clazz.equals(PriorityDtpExecutor.class)) { | ||
taskQueue = new PriorityBlockingQueue<>(props.getQueueCapacity(), PriorityDtpExecutor.getRunnableComparator()); | ||
} else if (clazz.equals(VirtualThreadExecutorProxy.class)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 虚拟线程判断可以提前判断、返回 |
||
int jdkVersion = JreEnum.currentVersion().ordinal(); | ||
if (jdkVersion < JDK_VERSION_21_OFFSET) { | ||
log.warn("DynamicTp virtual thread executor {} register warn: update your JDK version or don't use virtual thread executor!", props.getThreadPoolName()); | ||
int jreVersion = JreEnum.currentIntVersion(); | ||
if (jreVersion < JRE_VERSION_21) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我在springboot3分支加了判断版本大小方法,merge过来后可以使用 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
好 |
||
throw new UnsupportedOperationException(); | ||
} | ||
ThreadFactory factory = Thread.ofVirtual().name(props.getThreadPoolName()).factory(); | ||
return new Object[]{ | ||
Executors.newVirtualThreadPerTaskExecutor() | ||
Executors.newThreadPerTaskExecutor(factory) | ||
}; | ||
} else { | ||
taskQueue = buildLbq(props.getQueueType(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是"org.dromara.dynamictp.core.support.proxy.VirtualThreadExecutorProxy"换成VirtualThreadExecutorProxy.class.getName()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是指反过来equal对不