Skip to content

Commit 881b1a3

Browse files
committed
call MoreExecutors#shutdownAndAwaitTermination for timed out executors
1 parent ac5e60b commit 881b1a3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

symja_android_library/matheclipse-io/src/main/java/org/matheclipse/io/servlet/AJAXQueryServlet.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.matheclipse.parser.client.ParserConfig;
4545
import org.matheclipse.parser.client.SyntaxError;
4646
import org.matheclipse.parser.client.math.MathException;
47+
import com.google.common.util.concurrent.MoreExecutors;
4748
import jakarta.servlet.ServletException;
4849
import jakarta.servlet.http.HttpServlet;
4950
import jakarta.servlet.http.HttpServletRequest;
@@ -200,13 +201,17 @@ private String[] calculateString(EvalEngine engine, final String inputString,
200201
});
201202

202203
try {
203-
return
204-
task.get(Config.SERVER_REQUEST_TIMEOUT_SECONDS * 1000, TimeUnit.MILLISECONDS);
204+
return task.get(Config.SERVER_REQUEST_TIMEOUT_SECONDS * 1000, TimeUnit.MILLISECONDS);
205205
} catch (InterruptedException e) {
206206
return JSONBuilder.createJSONError("Timeout exceeded. Calculation interrupted!");
207207
} catch (ExecutionException | TimeoutException e) {
208208
engine.setStopRequested(true);
209209
return JSONBuilder.createJSONError("Timeout exceeded. Calculation aborted!");
210+
} finally {
211+
if (!task.cancel(true)) {
212+
LOGGER.warn("task.cancel() failed!");
213+
}
214+
MoreExecutors.shutdownAndAwaitTermination(executors, 1, TimeUnit.SECONDS);
210215
}
211216
}
212217

0 commit comments

Comments
 (0)