Is it possible to return from a java method that started threads before all the threads are done?
Here's my code:
import java.util.concurrent.*;
public class ExecutorSample {
public static void main(String[] args) {
ExecutorService service = Executors.newCachedThreadPool();
for (int i = 0; i < 10; i++) {
service.execute(() -> {
while (true) {
}
});
}
return;
}
}
This doesn't return for some reason that I don't understand. Why is the main thread's return affected by the worker threads being stuck?