Skip to content

Handle SimpleAsyncTaskExecutor in WebSocketMessageBrokerStats #33104

@csh0034

Description

@csh0034

When using the following executor with virtual threads:

SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
executor.setVirtualThreads(true);

The WebSocketMessageBrokerStats#getExecutorStatsInfo method returns "unknown".

private String getExecutorStatsInfo(@Nullable Executor executor) {
  if (executor == null) {
    return "null";
  }

  if (executor instanceof ThreadPoolTaskExecutor threadPoolTaskScheduler) {
    executor = threadPoolTaskScheduler.getThreadPoolExecutor();
  }

  if (executor instanceof ThreadPoolExecutor) {
    // It is assumed that the implementation of toString() in ThreadPoolExecutor
    // generates text that ends similar to the following:
    // pool size = #, active threads = #, queued tasks = #, completed tasks = #]
    String str = executor.toString();
    int indexOfPool = str.indexOf("pool");
    if (indexOfPool != -1) {
      // (length - 1) omits the trailing "]"
      return str.substring(indexOfPool, str.length() - 1);
    }
  }

  return "unknown";
}

It seems that only thread-pooling TaskExecutor was considered originally.
How about changing the wording?

Currently, it seems that there is no way to know if SimpleAsyncTaskExecutor is using virtual threads.

Metadata

Metadata

Assignees

Labels

in: messagingIssues in messaging modules (jms, messaging)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions