On Thu, 26 Oct 2023 22:34:24 GMT, Leonid Mesnik <lmes...@openjdk.org> wrote:

>> test/jtreg_test_thread_factory/src/share/classes/Virtual.java line 37:
>> 
>>> 35:             // The virtual threads don't belong to any group and need 
>>> global handler.
>>> 36:             Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
>>> 37:                     if (e instanceof ThreadDeath) {
>> 
>> `ThreadDeath` has been deprecated for removal since Java 20, so this should 
>> no longer be needed.
>
> It is still used in tests and we should ignore it like jtreg doing.

Shouldn't this code first retrieve the current default exception handler, and 
then check whether t is a virtual thread, and if so handle the exception as 
appropriate (not sure System.exit is appropriate ..). Then for non-virtual 
threads it delegates to the previous default handler.

final UncaughtExceptionHandler originalUEH = 
Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
        if (t.isVirtual()) {
            // ...
        } else {
            originalUEH.uncaughtException(t, e);
        }
});

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16369#discussion_r1374102902

Reply via email to