From 41d463e964168c670924366d8e8cf1c44475c81a Mon Sep 17 00:00:00 2001 From: Ryan Duryea Date: Fri, 29 May 2015 12:53:33 -0700 Subject: [PATCH] Add Launcher classes for WhiteRabbit and RiaH The Launcher class will replace the need for scripts to launch the JAR files with enough memory allocated Found this trick at: http://silentdevelopment.blogspot.com/2010/03/how-to-set-or-increase-xmx-heap-memory.html --- build.xml | 4 +-- .../ohdsi/utilities/RabbitInAHatLauncher.java | 25 +++++++++++++++++++ .../ohdsi/utilities/WhiteRabbitLauncher.java | 25 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/org/ohdsi/utilities/RabbitInAHatLauncher.java create mode 100644 src/org/ohdsi/utilities/WhiteRabbitLauncher.java diff --git a/build.xml b/build.xml index a2945b1e..3a608ffc 100644 --- a/build.xml +++ b/build.xml @@ -21,7 +21,7 @@ - + @@ -29,7 +29,7 @@ - + diff --git a/src/org/ohdsi/utilities/RabbitInAHatLauncher.java b/src/org/ohdsi/utilities/RabbitInAHatLauncher.java new file mode 100644 index 00000000..75e39681 --- /dev/null +++ b/src/org/ohdsi/utilities/RabbitInAHatLauncher.java @@ -0,0 +1,25 @@ +package org.ohdsi.utilities; + +import org.ohdsi.rabbitInAHat.RabbitInAHatMain; + +/* Adapted from code found on: + * http://silentdevelopment.blogspot.com/2010/03/how-to-set-or-increase-xmx-heap-memory.html + */ +public class RabbitInAHatLauncher { + private final static int MIN_HEAP = 1500; + + public static void main(String[] args) throws Exception { + + float heapSizeMegs = (Runtime.getRuntime().maxMemory() / 1024) / 1024; + + if (heapSizeMegs > MIN_HEAP) { + System.out.println("Launching with current VM"); + RabbitInAHatMain.main(args); + } else { + System.out.println("Starting new VM"); + String pathToJar = RabbitInAHatMain.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); + ProcessBuilder pb = new ProcessBuilder("java", "-Xmx" + MIN_HEAP + "m", "-classpath", pathToJar, "org.ohdsi.rabbitInAHat.RabbitInAHatMain"); + pb.start(); + } + } +} diff --git a/src/org/ohdsi/utilities/WhiteRabbitLauncher.java b/src/org/ohdsi/utilities/WhiteRabbitLauncher.java new file mode 100644 index 00000000..340dfb12 --- /dev/null +++ b/src/org/ohdsi/utilities/WhiteRabbitLauncher.java @@ -0,0 +1,25 @@ +package org.ohdsi.utilities; + +import org.ohdsi.whiteRabbit.WhiteRabbitMain; + +/* Adapted from code found on: + * http://silentdevelopment.blogspot.com/2010/03/how-to-set-or-increase-xmx-heap-memory.html + */ +public class WhiteRabbitLauncher { + private final static int MIN_HEAP = 1500; + + public static void main(String[] args) throws Exception { + + float heapSizeMegs = (Runtime.getRuntime().maxMemory() / 1024) / 1024; + + if (heapSizeMegs > MIN_HEAP) { + System.out.println("Launching with current VM"); + WhiteRabbitMain.main(args); + } else { + System.out.println("Starting new VM"); + String pathToJar = WhiteRabbitMain.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); + ProcessBuilder pb = new ProcessBuilder("java", "-Xmx" + MIN_HEAP + "m", "-classpath", pathToJar, "org.ohdsi.whiteRabbit.WhiteRabbitMain"); + pb.start(); + } + } +}