isVirtualWorkExecutor

This commit is contained in:
redkale
2023-10-16 15:02:20 +08:00
parent a32586bf3b
commit 6d63798ccf
2 changed files with 9 additions and 3 deletions

View File

@@ -2684,6 +2684,11 @@ public final class Application {
return workExecutor; return workExecutor;
} }
public boolean isVirtualWorkExecutor() {
//JDK21+
return workExecutor != null && workExecutor.getClass().getSimpleName().contains("ThreadPerTaskExecutor");
}
public AsyncGroup getClientAsyncGroup() { public AsyncGroup getClientAsyncGroup() {
return clientAsyncGroup; return clientAsyncGroup;
} }

View File

@@ -102,13 +102,14 @@ public abstract class MessageAgent implements Resourcable {
this.name = checkName(config.getValue("name", "")); this.name = checkName(config.getValue("name", ""));
this.httpAppRespTopic = generateHttpAppRespTopic(); this.httpAppRespTopic = generateHttpAppRespTopic();
this.sncpAppRespTopic = generateSncpAppRespTopic(); this.sncpAppRespTopic = generateSncpAppRespTopic();
int threads = config.getIntValue("threads", -1); int threads = config.getIntValue("threads", application.isVirtualWorkExecutor() ? 0 : -1);
if (threads == 0) { if (threads == 0) {
this.workExecutor = application.getWorkExecutor(); this.workExecutor = application.getWorkExecutor();
} }
if (this.workExecutor == null) { if (this.workExecutor == null) {
this.workExecutor = threads > 0 ? WorkThread.createExecutor(threads, "Redkale-MessageConsumerThread-[" + name + "]-%s") String namePrefix = Utility.isEmpty(name) ? "" : ("-" + name);
: WorkThread.createWorkExecutor(Utility.cpus(), "Redkale-MessageConsumerThread-[" + name + "]-%s"); this.workExecutor = threads > 0 ? WorkThread.createExecutor(threads, "Redkale-MessageConsumerThread" + namePrefix + "-%s")
: WorkThread.createWorkExecutor(Utility.cpus(), "Redkale-MessageConsumerThread" + namePrefix + "-%s");
} }
this.httpMessageClient = new MessageClient("http", this, this.httpAppRespTopic); this.httpMessageClient = new MessageClient("http", this, this.httpAppRespTopic);
this.sncpMessageClient = new MessageClient("sncp", this, this.sncpAppRespTopic); this.sncpMessageClient = new MessageClient("sncp", this, this.sncpAppRespTopic);