Skip to content

Commit

Permalink
Add Launcher classes for WhiteRabbit and RiaH
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aguynamedryan committed May 29, 2015
1 parent 9f629fd commit 41d463e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

<jar destfile="${build.dir}/WhiteRabbit.jar">
<manifest>
<attribute name="Main-Class" value="org.ohdsi.whiteRabbit.WhiteRabbitMain"/>
<attribute name="Main-Class" value="org.ohdsi.utilities.WhiteRabbitLauncher"/>
<attribute name="Class-Path" value=". WhiteRabbit_lib/ojdbc5.jar WhiteRabbit_lib/ojdbc6.jar WhiteRabbit_lib/sqljdbc4.jar WhiteRabbit_lib/mysql-connector-java-5.1.30-${build.dir}.jar WhiteRabbit_lib/dom4j-1.6.1.jar WhiteRabbit_lib/poi-3.9-20121203.jar WhiteRabbit_lib/poi-excelant-3.9-20121203.jar WhiteRabbit_lib/poi-ooxml-3.9-20121203.jar WhiteRabbit_lib/poi-ooxml-schemas-3.9-20121203.jar WhiteRabbit_lib/stax-api-1.0.1.jar WhiteRabbit_lib/xmlbeans-2.3.0.jar WhiteRabbit_lib/jtds-1.2.7.jar WhiteRabbit_lib/postgresql-9.3-1101.jdbc4.jar WhiteRabbit_lib/postgresql-9.3-1101.jdbc41.jar"/>
</manifest>
<fileset dir="${build.dir}"/>
<fileset dir="${src.dir}" includes="**/*.csv,**/*.png" />
</jar>
<jar destfile="${build.dir}/RabbitInAHat.jar">
<manifest>
<attribute name="Main-Class" value="org.ohdsi.rabbitInAHat.RabbitInAHatMain"/>
<attribute name="Main-Class" value="org.ohdsi.utilities.RabbitInAHatLauncher"/>
<attribute name="Class-Path" value=". WhiteRabbit_lib/ojdbc5.jar WhiteRabbit_lib/ojdbc6.jar WhiteRabbit_lib/sqljdbc4.jar WhiteRabbit_lib/mysql-connector-java-5.1.30-${build.dir}.jar WhiteRabbit_lib/dom4j-1.6.1.jar WhiteRabbit_lib/poi-3.9-20121203.jar WhiteRabbit_lib/poi-excelant-3.9-20121203.jar WhiteRabbit_lib/poi-ooxml-3.9-20121203.jar WhiteRabbit_lib/poi-ooxml-schemas-3.9-20121203.jar WhiteRabbit_lib/stax-api-1.0.1.jar WhiteRabbit_lib/xmlbeans-2.3.0.jar WhiteRabbit_lib/jtds-1.2.7.jar WhiteRabbit_lib/postgresql-9.3-1101.jdbc4.jar WhiteRabbit_lib/postgresql-9.3-1101.jdbc41.jar WhiteRabbit_lib/json-io-3.0.1.jar"/>
</manifest>
<fileset dir="${build.dir}"/>
Expand Down
25 changes: 25 additions & 0 deletions src/org/ohdsi/utilities/RabbitInAHatLauncher.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
25 changes: 25 additions & 0 deletions src/org/ohdsi/utilities/WhiteRabbitLauncher.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

0 comments on commit 41d463e

Please sign in to comment.