Skip to content

Conversation

@SentryMan
Copy link
Contributor

@SentryMan SentryMan commented Nov 5, 2025

  • Use Method Handles to invoke Thread.ofVirtual().name(threadBaseName, 0).factory() when on jdk 24+.
  • create a new class VirtualExecutor to reflectively create thread per task executors
  • replace non scheduled thread pools with virtual thread executors

part of #53

@corite
Copy link

corite commented Nov 5, 2025

I've had a quick look over your proposed changes (note that I'm not very familiar with kwik as a project, but I have worked quite a bit with VirtualThreads). I think the changes look good, as far as that it shouldn't break anything, but I think it falls a bit short conceptually. Currently the factory which you have changed supplies several ThreadPools in kwik. Generally speaking, you should never pool VirtualThreads, because pooling as a concept only makes sense for expensive resources. A PlatformThread (i.e. a normal OS thread) is an expensive resource, a VirtualThread however is not (the bookkeeping effort of pooling the thread may very much outweigh to cost of creating a new one). So in my opinion, if you want to introduce VirtualThreads, you should also adapt the ThreadPools which consume them (i.e. probably just make them non-caching in JDK24+).

You also don't have to take my word for this, the original JEP which introduced VirtualThreads in JDK 21 already makes that argument. It also goes into quite some detail about what the mental model for this feature is, and even though some things (mostly limitations like monitor pinning) have changed since JDK 21, I think it still gives a good birds-eye view of the whole situation. I think it's definitely worth a read if your looking to implement something on top of VirtualThreads.

(this is not meant as criticism, I was just pinged by your issue comment and wanted to offer my two cents on the topic :) )

@SentryMan
Copy link
Contributor Author

SentryMan commented Nov 5, 2025

the factory which you have changed supplies several ThreadPools in kwik

Yeah I was going to do a follow up to modify all of those cached threadpools into thread per task executors. For the scheduled executors I figured there was no harm in using a virtual thread factory,.

@SentryMan
Copy link
Contributor Author

though I suppose there is no need to wait

@SentryMan SentryMan changed the title Use Virtual Daemons when on JDK 24+ Use Virtual Threads when on JDK 24+ Nov 5, 2025
@SentryMan
Copy link
Contributor Author

@ptrd what do we think about this?

mechite added a commit to mechite/kwik that referenced this pull request Jan 13, 2026
This merges two files as-is from the related PR.

It then uses the new `VirtualExecutor` system where the single-thread
executor was previously being used as part of these async changes.

Related-to: ptrd#74
Co-authored-by: Josiah Noel <32279667+SentryMan@users.noreply.github.com>
Signed-off-by: Mahied Maruf <contact@mechite.com>
@mechite mechite mentioned this pull request Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants