thunkware / virtual-threads-bridge

Use Java21's Virtual Threads API in Java 8+
MIT License
6 stars 3 forks source link

[suggestion] Customize the threads of virtual threads #3

Closed ferblaca closed 8 months ago

ferblaca commented 9 months ago

It would be great if the API supported being able to set the name and uncaughtExceptionHandler of the threads that are created with the Virtual Threads factory.

The Java21 API supports thread customization in the following way: Thread.ofVirtual().name("my-custom-vt-name").uncaughtExceptionHandler(handler).factory();.

I think the easiest way would be for the ExecutorTool to support the creation of the ThreadFactory and to be able to set at least the name and the uncaughtExceptionHandler, for example: ExecutorTool.newThreadFactory().name("my-custom-name").uncaughtExceptionHandler(customHandler).factory()

maxxedev commented 8 months ago

Upcoming release will allow you to do this:

ThreadTool.ofVirtual().name("my-custom-vt-name").uncaughtExceptionHandler(handler).factory();