Skip to content

Instantly share code, notes, and snippets.

@franz1981
Created November 2, 2023 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save franz1981/538367e9eaa6b490b1bf71245f8e28bc to your computer and use it in GitHub Desktop.
Save franz1981/538367e9eaa6b490b1bf71245f8e28bc to your computer and use it in GitHub Desktop.
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Main {
static {
System.out.println("here we go...");
try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
executor.submit(() -> {}).get();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("...fiuuu!");
}
public static void main(String[] args) {
}
}
@franz1981
Copy link
Author

Run me on Java 21 with:

java Main.java

and it never completes

@theRealAph
Copy link

What fun. I seem to have reproduced the bug here. I'll look later today

@franz1981
Copy link
Author

break-it Franz, that's my second name :D

@franz1981
Copy link
Author

franz1981 commented Nov 3, 2023

So a class loader deadlock, which, by turning the runnable lambda into a proper anonymous class, won't happen anymore...

eg

    static {
    	System.out.println("here we go...");	
        try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
            executor.submit(new Runnable() {
            
              public void run() {
              }
            }).get();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
    	System.out.println("...fiuuu!");
    }

@theRealAph
Copy link

Might not happen any more. Your bullet, your gun, your foot.

@franz1981
Copy link
Author

...and all the fun, ihih

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment