File tree Expand file tree Collapse file tree 2 files changed +33
-7
lines changed
src/java.base/share/classes/java/util/concurrent
test/jdk/java/util/concurrent/tck Expand file tree Collapse file tree 2 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -3452,22 +3452,30 @@ private DelayScheduler startDelayScheduler() {
34523452 String name = poolName + "-delayScheduler" ;
34533453 if (workerNamePrefix == null )
34543454 asyncCommonPool (); // override common parallelism zero
3455- lockRunState ();
3455+ long isShutdown = lockRunState () & SHUTDOWN ;
34563456 try {
3457- if ((ds = delayScheduler ) == null ) {
3457+ if (isShutdown == 0L && (ds = delayScheduler ) == null ) {
34583458 ds = delayScheduler = new DelayScheduler (this , name );
34593459 start = true ;
34603460 }
34613461 } finally {
34623462 unlockRunState ();
34633463 }
34643464 if (start ) { // start outside of lock
3465- // exceptions on start passed to (external) callers
34663465 SharedThreadContainer ctr ;
3467- if ((ctr = container ) != null )
3468- ctr .start (ds );
3469- else
3470- ds .start ();
3466+ try {
3467+ if ((ctr = container ) != null )
3468+ ctr .start (ds );
3469+ else
3470+ ds .start ();
3471+ } catch (RuntimeException | Error ex ) { // back out
3472+ lockRunState ();
3473+ ds = delayScheduler = null ;
3474+ unlockRunState ();
3475+ tryTerminate (false , false );
3476+ if (ex instanceof Error )
3477+ throw ex ;
3478+ }
34713479 }
34723480 }
34733481 return ds ;
Original file line number Diff line number Diff line change @@ -644,4 +644,22 @@ public Boolean realCall() {
644644 }
645645 }
646646
647+ /**
648+ * schedule throws RejectedExecutionException if shutdown before
649+ * first delayed task is submitted
650+ */
651+ public void testInitialScheduleAfterShutdown () throws InterruptedException {
652+ Runnable r = new NoOpRunnable ();
653+ boolean rje = false ;
654+ try (final ForkJoinPool p = new ForkJoinPool (1 )) {
655+ p .shutdown ();
656+ assertTrue (p .awaitTermination (LONG_DELAY_MS , MILLISECONDS ));
657+ try {
658+ p .schedule (r , 1 , MILLISECONDS );
659+ } catch (RejectedExecutionException ok ) {
660+ rje = true ;
661+ }
662+ }
663+ assertTrue (rje );
664+ }
647665}
You can’t perform that action at this time.
0 commit comments