Skip to content

Remove Thread.stop() which is deprecated in recent java versions. #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
22 changes: 17 additions & 5 deletions src/main/java/org/ojalgo/benchmark/AbstractBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,16 @@ protected static void doBenchmark(final Set<ModelSolverPair> allWork, final Conf
AtomicBoolean working = new AtomicBoolean(false);

Thread worker = new Thread(() -> {

while (!subResults.isStable()) {
subResults.add(AbstractBenchmark.meassure(simplified));
try {
while (!subResults.isStable() && !Thread.currentThread().isInterrupted()) {
subResults.add(AbstractBenchmark.meassure(simplified));
}
} catch (Exception e) {
// Handle interruption or other exceptions
BasicLogger.debug("Worker thread interrupted or exception occurred: {}", e.getMessage());
} finally {
working.set(false);
}
working.set(false);
});

working.set(true);
Expand All @@ -356,7 +361,14 @@ protected static void doBenchmark(final Set<ModelSolverPair> allWork, final Conf
Thread.sleep(1_000L);
}

worker.stop();
worker.interrupt();
// Give the worker thread a chance to clean up
try {
worker.join(1000); // Wait up to 1 second for the thread to terminate
} catch (InterruptedException e) {
// Handle interruption by ignoring it and continuing with the next benchmark.
BasicLogger.debug("Worker thread.join() sent interrupt: {}", e.getMessage());
}
working.set(false);

if (subResults.fastest != null) {
Expand Down