Skip to content
Snippets Groups Projects
Commit ac41323d authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

SCAN-958: don't call System.gc(), and exit in case of OutOfMemoryError with invisible salsa frame

parent 50492a26
Branches
Tags
No related merge requests found
......@@ -78,6 +78,12 @@ public class Salsa {
SPLASH.setAlwaysOnTop(true);
}
private static JFrame salsaFrame;
public static JFrame getSalsaFrame() {
return salsaFrame;
}
private static void printCorrectUsageAndExit(final SalsaPreferencesException salsaPreferencesException) {
StringBuilder builder = new StringBuilder("\n----- Wrong Salsa Parameters! -----\n");
if (salsaPreferencesException != null) {
......@@ -232,6 +238,7 @@ public class Salsa {
titleBuilder.append(" read only");
JFrame frame = new JFrame();
salsaFrame = frame;
frame.setIconImages(ICONS_LIST);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle(titleBuilder.toString());
......@@ -248,6 +255,7 @@ public class Salsa {
private static void launchSalsa(String configName, String perspectiveName, boolean resultMode) {
SPLASH.addProgress(String.format(ApplicationController.BUILDING_CONTROLLER, "..."));
ApplicationController applicationController = new ApplicationController(resultMode);
salsaFrame = applicationController.getView();
applicationController.getView().setIconImages(ICONS_LIST);
SwingUtilities.invokeLater(() -> {
......
......@@ -364,7 +364,7 @@ public class ApplicationView extends JFrame implements IView<ApplicationControll
memory = (t instanceof OutOfMemoryError);
if (memory) {
oome = true;
System.gc();
// SCAN-958: don't call System.gc() to avoid consuming CPU
SwingUtilities.invokeLater(() -> {
if ((bottomPanel != null) && (bottomPanelLayout != null) && (oomeLabel != null)) {
bottomPanelLayout.show(bottomPanel, OOME_VIEW);
......@@ -372,8 +372,16 @@ public class ApplicationView extends JFrame implements IView<ApplicationControll
});
}
} finally {
LOGGER.error(memory ? String.format(OOME_SIMPLE, thread)
: String.format(DEFAULT_ERROR, t.getClass().getSimpleName(), thread), t);
if (memory) {
LOGGER.error(String.format(OOME_SIMPLE, thread), t);
// SCAN-958: In case of OutOfMemoryError, exit if main frame does not exist or is not visible.
JFrame mainFrame = Salsa.getSalsaFrame();
if ((mainFrame == null) || !mainFrame.isShowing()) {
System.exit(1);
}
} else {
LOGGER.error(String.format(DEFAULT_ERROR, t.getClass().getSimpleName(), thread), t);
}
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment