@@ -35,7 +35,8 @@ public class MultiProvider extends EventProvider {
3535 @ Getter
3636 private static final String NAME = "multiprovider" ;
3737
38- public static final int INIT_THREADS_COUNT = 8 ;
38+ // Use CPU count as upper bound for init threads.
39+ public static final int INIT_THREADS_COUNT = Runtime .getRuntime ().availableProcessors ();
3940
4041 private final Map <String , FeatureProvider > providers ;
4142 private final Strategy strategy ;
@@ -68,7 +69,7 @@ protected static Map<String, FeatureProvider> buildProviders(List<FeatureProvide
6869 FeatureProvider prevProvider =
6970 providersMap .put (provider .getMetadata ().getName (), provider );
7071 if (prevProvider != null ) {
71- log .warn ("duplicated provider name: {}" , provider .getMetadata ().getName ());
72+ log .info ("duplicated provider name: {}" , provider .getMetadata ().getName ());
7273 }
7374 }
7475 return Collections .unmodifiableMap (providersMap );
@@ -92,7 +93,8 @@ public void initialize(EvaluationContext evaluationContext) throws Exception {
9293 return ;
9394 }
9495
95- ExecutorService executorService = Executors .newFixedThreadPool (Math .min (INIT_THREADS_COUNT , providers .size ()));
96+ ExecutorService executorService =
97+ Executors .newFixedThreadPool (Math .min (INIT_THREADS_COUNT , providers .size ()));
9698 try {
9799 Collection <Callable <Void >> tasks = new ArrayList <>(providers .size ());
98100 for (FeatureProvider provider : providers .values ()) {
@@ -113,17 +115,12 @@ public void initialize(EvaluationContext evaluationContext) throws Exception {
113115 result .get ();
114116 }
115117 } catch (Exception e ) {
116- // If initialization fails for any provider, attempt to shut down all providers
117- // to avoid a partial/limbo state.
118- for (FeatureProvider provider : providers .values ()) {
119- try {
120- provider .shutdown ();
121- } catch (Exception shutdownEx ) {
122- log .error (
123- "error shutting down provider {} after failed initialize" ,
124- provider .getMetadata ().getName (),
125- shutdownEx );
126- }
118+ // If initialization fails for any provider, attempt to shut down via the
119+ // standard shutdown path to avoid a partial/limbo state.
120+ try {
121+ shutdown ();
122+ } catch (Exception shutdownEx ) {
123+ log .error ("error during shutdown after failed initialize" , shutdownEx );
127124 }
128125 throw e ;
129126 } finally {
0 commit comments