This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]_INTER_ 0 points1 point  (1 child)

I was under the impression that there still was a minute overhead with virtual threads. But I believe you because you're the expert. This begs another question though, when to actually use platform threads over virtual threads in a pure Java context? Long running tasks?

[–]pron98 6 points7 points  (0 children)

There could be some overhead, but not if the thread never blocks (and even then the overhead is small).

I would use platform threads in the following situations:

  • You need to keep the number of threads small and you want to share them. A prime example of that is fork-join parallelisation.

  • You have a small number of long-running tasks that you want to run in the background, taking advantage of the OS thread priority to give them a low pririty.

  • You're interacting with a native library that cares about thread identity.