Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
set -oe pipefail
jarPath=$1
# inspired by metabase
# Disable limit to amount of time spent in GC. Better slow than not working at all
JAVA_OPTS="$JAVA_OPTS -XX:-UseGCOverheadLimit"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"
JAVA_OPTS="$JAVA_OPTS -XX:+CMSClassUnloadingEnabled"
# Use 32-bit pointers. Reduces memory usage and GC events
JAVA_OPTS="$JAVA_OPTS -XX:+UseCompressedOops"
JAVA_OPTS="$JAVA_OPTS -XX:+UseCompressedClassPointers"
# Heap settings, as dicated by the container memory limits
# max and min heap set to X% of what container gives us
# by default it's 70%, can be overriden via HEAP_PERCENTAGE env var
HEAP_PERCENTAGE=${HEAP_PERCENTAGE:-70}
JAVA_OPTS="$JAVA_OPTS -XX:InitialRAMPercentage=${HEAP_PERCENTAGE}"
JAVA_OPTS="$JAVA_OPTS -XX:MaxRAMPercentage=${HEAP_PERCENTAGE}"
# don't try to start AWT. Not sure this does anything but better safe than wasting memor
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"
# always UTF
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8"
# always assume UTC
JAVA_OPTS="$JAVA_OPTS -Duser.timezone=UTC"
echo "Starting $jarPath"
java $JAVA_OPTS -jar $jarPath 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment