title: How to run spring boot fat jar with minimal memory?
body: <p>Here is our maven <strong>MediSpan</strong> project. Actually it's a <code>REST</code> web service. Its return <code>JSON</code> object for Drug Drug Interaction query through <strong>GPI</strong> code for a specified patient. Here is an sample of an rest query:</p>
  
  <pre><code>http://localhost:8017/mspn/query?pid=1000&amp;
  gpis=83-20-00-30-20-03-10&amp;gpis=64-99-10-02-12-03-20
  </code></pre>
  
  <p>Here is the structure of our project:</p>
  
  <pre><code>/opt/java/spring/boot/fat/jar/project/chorke─mspn─server/
      ├─ MediSpan.Documents.Monograph.css                   [     1,697 Byte]
      ├─ MediSpan.Documents.Monograph.xslt                  [    35,167 Byte]
      ├─ bitronix-tx-mgr-log-001                            [ 2,097,173 Byte]
      ├─ bitronix-tx-mgr-log-002                            [ 2,097,173 Byte]
      └─ chorke─mspn─server.jar!                            [26,022,610 Byte]
          ├─ medispan/                                      [   443,756 Byte]
          ├─ META-INF/                                      [    33,702 Byte]
          ├─ org/springframework/boot/loader/               [   165,003 Byte]
          ├─ com/chorke/                                    [    27,633 Byte]
          ├─ application.properties                         [       501 Byte]
          ├─ application.yml                                [     2,234 Byte]
          ├─ MediSpan.Foundation.Config.xml                 [    14,939 Byte]
          ├─ MediSpan.Foundation.Text.xml                   [     9,003 Byte]
          ├─ log4j.xml                                      [     2,254 Byte]
          └─ lib/                                           [25,688,056 Byte]
              ├─ aopalliance-1.0.jar
              ├─ btm-2.1.4.jar
              ├─ c3p0-0.9.1.2.jar
              ├─ camel-core-2.15.2.jar
              ├─ camel-jasypt-2.15.2.jar
              ├─ camel-quartz2-2.15.2.jar
              ├─ camel-spring-2.15.2.jar
              ├─ camel-spring-javaconfig-2.15.2.jar
              ├─ chorke-comn-spring-2.0.00-SNAPSHOT.jar     [    11,698 Byte]
              ├─ chorke-mspn-entity-2.0.00-SNAPSHOT.jar     [    13,486 Byte]
              ├─ chorke-mspn-parser-2.0.00-SNAPSHOT.jar     [    15,921 Byte]
              ├─ chorke-mspn-persis-2.0.00-SNAPSHOT.jar     [    23,328 Byte]
              ├─ chorke-mspn-utlity-2.0.00-SNAPSHOT.jar     [    25,684 Byte]
              ├─ commons-lang3-3.3.2.jar
              ├─ commons-logging-1.1.1.jar
              ├─ ehcache-core-2.6.11.jar
              ├─ jackson-annotations-2.4.6.jar
              ├─ jackson-core-2.4.6.jar
              ├─ jackson-databind-2.4.6.jar
              ├─ jasypt-1.9.2.jar
              ├─ javax.transaction-api-1.2.jar
              ├─ jaxb-core-2.2.11.jar
              ├─ jaxb-impl-2.2.11.jar
              ├─ log4j-1.2.17.jar
              ├─ medispan-business-5.1.10.jar
              ├─ medispan-concepts-5.1.10.jar
              ├─ medispan-conditions-5.1.10.jar
              ├─ medispan-documents-5.1.10.jar
              ├─ medispan-interactions-5.1.10.jar
              ├─ medispan-screening-5.1.10.jar
              ├─ medispan-utility-5.1.10.jar
              ├─ mybatis-3.2.8.jar
              ├─ mybatis-ehcache-1.0.2.jar
              ├─ mybatis-spring-1.2.2.jar
              ├─ ojdbc6-11.2.0.3.jar
              ├─ org.apache.servicemix.bundles.cglib-2.1_3_7.jar
              ├─ quartz-2.2.1.jar
              ├─ slf4j-api-1.7.12.jar
              ├─ slf4j-log4j12-1.7.12.jar
              ├─ snakeyaml-1.14.jar
              ├─ spring-aop-4.1.6.RELEASE.jar
              ├─ spring-beans-4.1.6.RELEASE.jar
              ├─ spring-boot-1.2.4.RELEASE.jar
              ├─ spring-boot-actuator-1.2.4.RELEASE.jar
              ├─ spring-boot-autoconfigure-1.2.4.RELEASE.jar
              ├─ spring-boot-starter-1.2.4.RELEASE.jar
              ├─ spring-boot-starter-actuator-1.2.4.RELEASE.jar
              ├─ spring-boot-starter-tomcat-1.2.4.RELEASE.jar
              ├─ spring-context-4.1.6.RELEASE.jar
              ├─ spring-context-support-4.1.6.RELEASE.jar
              ├─ spring-core-4.1.6.RELEASE.jar
              ├─ spring-expression-4.1.6.RELEASE.jar
              ├─ spring-jdbc-4.1.6.RELEASE.jar
              ├─ spring-jms-4.1.6.RELEASE.jar
              ├─ spring-messaging-4.1.6.RELEASE.jar
              ├─ spring-tx-4.1.6.RELEASE.jar
              ├─ spring-web-4.1.6.RELEASE.jar
              ├─ spring-webmvc-4.1.6.RELEASE.jar
              ├─ tomcat-embed-core-8.0.23.jar
              ├─ tomcat-embed-el-8.0.23.jar
              ├─ tomcat-embed-logging-juli-8.0.23.jar
              └─ tomcat-embed-websocket-8.0.23.jar
  </code></pre>
  
  <p>Here is the command of running this fat jar project and their matrix:</p>
  
  <pre><code># without setting java option
  java -jar chorke-mspn-server.jar
  </code></pre>
  
  <p>Started BootstrapApplication in 41.824 seconds (JVM running for 42.807)</p>
  
  <ul>
  <li><strong>Memory Used:</strong> 532,858 kbytes</li>
  <li><strong>Committed:</strong> 751,616 kbytes</li>
  <li><strong>Max:</strong> 1,847,808 kbytes</li>
  <li><em>9502 classes loaded</em></li>
  </ul>
  
  <p>Working fine.</p>
  
  <pre><code># setting java option for 1024 MB
  java -Xmx1024M -XX:MaxPermSize=768M -XX:+CMSClassUnloadingEnabled \
  -jar chorke-mspn-server.jar
  </code></pre>
  
  <p>Started BootstrapApplication in 42.134 seconds (JVM running for 43.084)</p>
  
  <ul>
  <li><strong>Memory Used:</strong> 160,016 kbytes</li>
  <li><strong>Committed:</strong> 422,912 kbytes</li>
  <li><strong>Max:</strong> 932,352 kbytes</li>
  <li><em>9505 classes loaded</em></li>
  </ul>
  
  <p>Working fine.</p>
  
  <pre><code># setting java option for 512 MB
  java -Xmx512M -XX:MaxPermSize=384M -XX:+CMSClassUnloadingEnabled \
  -jar chorke-mspn-server.jar
  </code></pre>
  
  <p>Started BootstrapApplication in 42.385 seconds (JVM running for 43.358)</p>
  
  <ul>
  <li><strong>Memory Used:</strong> 244,280 kbytes</li>
  <li><strong>Committed:</strong> 463,360 kbytes</li>
  <li><strong>Max:</strong> 465,920 kbytes</li>
  <li><em>9503 classes loaded</em></li>
  </ul>
  
  <p>Working fine.</p>
  
  <pre><code># setting java option for 256 MB
  java -Xmx256M -XX:MaxPermSize=192M -XX:+CMSClassUnloadingEnabled \
  -jar chorke-mspn-server.jar
  </code></pre>
  
  <p>Started BootstrapApplication in 42.202 seconds (JVM running for 43.174)</p>
  
  <ul>
  <li><strong>Memory Used:</strong> 244,280 kbytes</li>
  <li><strong>Committed:</strong> 463,360 kbytes</li>
  <li><strong>Max:</strong> 465,920 kbytes</li>
  <li><em>9503 classes loaded</em></li>
  </ul>
  
  <p>threw exception [Handler processing failed; nested exception is java.lang.OutOfMemoryError: GC overhead limit exceeded] with root cause</p>
  
  <pre><code>java.lang.OutOfMemoryError: GC overhead limit exceeded
          at java.lang.Integer.valueOf(Integer.java:642)
          at medispan.foundation.convert.ValueType.asValue(Unknown Source)
          at medispan.foundation.dataaccess.providers.sql.SQLProvider.executeForResults(Unknown Source)
          at medispan.foundation.dataaccess.providers.sql.SQLDataAccessProvider.innerExecuteForCollection(Unknown Source)
          at medispan.foundation.dataaccess.DataAccessProvider.executeForCollection(Unknown Source)
          at medispan.business.dataaccess.BusinessDataAccessManager.load(Unknown Source)
          at medispan.business.dataaccess.QueryPropertyValues.getPropertyValue(Unknown Source)
          at medispan.business.dataaccess.QueryPropertyValues.getInnerValue(Unknown Source)
          more..
  </code></pre>
  
  <p>This application consist with <em>embedded tomcat server</em>, <em>spring boot</em>, <em>spring mvc</em>, <em>myBatis</em>, <em>apache-camel</em>, <em>bitronix transaction manager</em>, <em>medispan</em>. we wish to run it on <strong>32~128</strong> <code>MB</code> memory. Could you please kind enough to suggest us for running this application with optimal/minimal of memory usage?</p>