Improve support for virtual thread detection by PerfectSlayer · Pull Request #9852 · DataDog/dd-trace-java

What Does This Do

This PR improves the environment component to be able to check for virtual threads support.

EDIT: Support was already added in #9537 then this PR only brings few additional elements compared to the original ThreadUtils:

  • A syntactic sugar helper for threadId() with current thread
  • Expose the newVirtualThreadPerTaskExecutor() ExecutorServices to allow its usage from core
  • Use JavaVirtualMachine.isJavaVersionAtLeast() instead of JavaVersion.getRuntimeVersion().isAtLeast() to avoid parsing version number multiple times
  • Change name from ThreadUtils to the ThreadSupport as there are already two ThreadUtils classes (datadog.trace.ThreadUtils and datadog.trace.agent.test.utils.ThreadUtils)

Motivation

With the adoption of modern Java versions, we will need to check for virtual threads to avoid expensive per-thread work or memory allocation (like ThreadLocals).

Additional Notes

Contributor Checklist

Jira ticket: [PROJ-IDENT]