import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class Main
{
public static void main(String[] args)
{
final ExecutorService executor = Executors.newFixedThreadPool(10);
executor.execute(new Runnable()
{
@Override
public void run()
{
for (int i = 0; i < 10; i++)
executor.execute(new Runnable()
{
@Override
public void run()
{
System.out.println("run");
}
});
}
});
executor.shutdown();
try
{
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
我得到RejectedExecutionException
是因为内部executor.execute
调用 after shutdown
。在这种情况下,我该如何等待执行人?