Skip to content

Commit

Permalink
First attempt at testing thread safety
Browse files Browse the repository at this point in the history
  • Loading branch information
yoquinjo committed Aug 24, 2023
1 parent 1ebf550 commit 4856116
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,18 @@ public void testBoosterInplacePredict() throws XGBoostError, IOException {
// Create thread pool
int n_tasks = 20;
List<Future<Boolean>> result = new ArrayList(n_tasks);
ExecutorService executorService = Executors.newFixedThreadPool(5); // Create pool of 5 threads

// Submit all the tasks
for (int i=0; i<n_tasks; i++) {
result.add(executorService.submit(new InplacePredictionTask(i, booster, testX2, test_rows, features, predicts)));
}

// Tell the executor service we are done
executorService.shutdown();
ExecutorService executorService = Executors.newFixedThreadPool(n_tasks); // Create pool of 20 threads
CountDownLatch latch = new CountDownLatch(n_tasks); // Latch for testing thread safety

try {
for (int i = 0; i < n_tasks; i++) {
int finalI = i;
executorService.execute(() -> {
result.add(executorService.submit(new InplacePredictionTask(finalI, booster, testX2, test_rows, features, predicts)));
latch.countDown();
});
}
latch.await();
executorService.awaitTermination(10, TimeUnit.SECONDS);

// Get the result from each Future returned and confirm success
Expand Down

0 comments on commit 4856116

Please sign in to comment.