@@ -87,19 +87,37 @@ public static void setDefaultExecutor() {
8787 setDefaultExecutor (scheduler );
8888 }
8989
90+ /**
91+ * Changes the default executor, and shuts the previous executor down.
92+ *
93+ * @param s the new executor
94+ */
9095 public static void setDefaultExecutor (Executor s ) {
91- if (s == DEFAULT_EXECUTOR ) {
96+ setDefaultExecutor (s , true );
97+ }
98+
99+ /**
100+ * Changes the default executor, and shuts the previous executor down when {@code shutdownPrevious} is {@code true}.
101+ *
102+ * @param executor the new executor
103+ * @param shutdownPrevious {@code true} when the previous executor needs to be shut down, {@code false} otherwise
104+ */
105+ public static void setDefaultExecutor (Executor executor , boolean shutdownPrevious ) {
106+ if (executor == DEFAULT_EXECUTOR ) {
92107 return ;
93108 }
94- Executor existing = DEFAULT_EXECUTOR ;
95- if (existing instanceof ExecutorService ) {
96- ((ExecutorService ) existing ).shutdownNow ();
97- }
98- if (DEFAULT_SCHEDULER != null ) {
99- DEFAULT_SCHEDULER .shutdownNow ();
109+ if (shutdownPrevious ) {
110+ Executor existing = DEFAULT_EXECUTOR ;
111+ if (existing instanceof ExecutorService ) {
112+ ((ExecutorService ) existing ).shutdownNow ();
113+ }
114+ if (DEFAULT_SCHEDULER != null ) {
115+ DEFAULT_SCHEDULER .shutdownNow ();
116+ }
100117 }
101- DEFAULT_EXECUTOR = s ;
102- DEFAULT_SCHEDULER = (s instanceof ScheduledExecutorService ) ? (ScheduledExecutorService ) s : new MutinyScheduler (s );
118+ DEFAULT_EXECUTOR = executor ;
119+ DEFAULT_SCHEDULER = (executor instanceof ScheduledExecutorService ) ? (ScheduledExecutorService ) executor
120+ : new MutinyScheduler (executor );
103121 }
104122
105123 public static ScheduledExecutorService getDefaultWorkerPool () {
0 commit comments