Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import dev.openfeature.sdk.Metadata;
import dev.openfeature.sdk.ProviderEvaluation;
import dev.openfeature.sdk.Value;
import dev.openfeature.sdk.exceptions.GeneralError;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -90,7 +89,7 @@ public void initialize(EvaluationContext evaluationContext) throws Exception {
json.put("name", NAME);
JSONObject providersMetadata = new JSONObject();
json.put("originalMetadata", providersMetadata);
ExecutorService initPool = Executors.newFixedThreadPool(INIT_THREADS_COUNT);

Collection<Callable<Boolean>> tasks = new ArrayList<>(providers.size());
for (FeatureProvider provider : providers.values()) {
tasks.add(() -> {
Expand All @@ -101,12 +100,19 @@ public void initialize(EvaluationContext evaluationContext) throws Exception {
providerMetadata.put("name", provider.getMetadata().getName());
providersMetadata.put(provider.getMetadata().getName(), providerMetadata);
}
List<Future<Boolean>> results = initPool.invokeAll(tasks);
for (Future<Boolean> result : results) {
if (!result.get()) {
throw new GeneralError("init failed");

ExecutorService initPool = Executors.newFixedThreadPool(INIT_THREADS_COUNT);
try {
List<Future<Boolean>> results = initPool.invokeAll(tasks);
// Wait for all provider initializations to complete.
// If any provider.initialize() throws, result.get() will throw ExecutionException.
for (Future<Boolean> result : results) {
result.get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should check for result.isCancelled(), and also add a sensible timeout result.get(timeout, TimeUnit.MILLISECONDS);.

}
} finally {
initPool.shutdown();
}

metadataName = json.toString();
}

Expand Down
Loading