0

Recently, I started using a Java application a former colleague of mine designed. After performing certain actions, the application freezes and the error.log file shows the following:

Exception in thread "Thread-4" java.lang.OutOfMemoryError: Java heap space
    at org.apache.poi.poifs.storage.BATBlock.<init>(BATBlock.java:57)
    at org.apache.poi.poifs.storage.BATBlock.<init>(BATBlock.java:210)
    at org.apache.poi.poifs.storage.BATBlock.createBATBlocks(BATBlock.java:87)
    at org.apache.poi.poifs.storage.BlockAllocationTableWriter.simpleCreateBlocks(BlockAllocationTableWriter.java:150)
    at org.apache.poi.poifs.storage.BlockAllocationTableWriter.createBlocks(BlockAllocationTableWriter.java:103)
    at org.apache.poi.poifs.filesystem.POIFSFileSystem.writeFilesystem(POIFSFileSystem.java:221)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:744)
    at net.ndmystko.qa.QAJobReporter.writeWorkbook(QAJobReporter.java:478)
    at net.ndmystko.qa.QAJobReporter.writeResults(QAJobReporter.java:458)
    at net.ndmystko.qa.QAJobReporter.writeResults(QAJobReporter.java:402)
    at net.ndmystko.qa.QA.displayEvolutionProgress(QA.java:1257)
    at net.ndmystko.qa.QA.access$9(QA.java:1186)
    at net.ndmystko.qa.QA$4.actionPerformed(QA.java:1176)
    at net.ndmystko.analysis.evolution.Evolution.run(Evolution.java:191)

I have read that I would need to increase the heap size allotted to the application. However, I do not know how to achieve this, or where I could enter the code needed. Any help would be greatly appreciated.

Note: I am not experienced in programming. I run the program from a .bat file.

user28664
  • 3
  • 4
  • 3
    Possible duplicate of [Increase heap size in Java](http://stackoverflow.com/questions/1565388/increase-heap-size-in-java) – Joe Clay Oct 18 '16 at 13:03

1 Answers1

3

You can use the following Java commandline parameters

-Xms: initial heap size
-Xmx: Maximum heap size

Set it when you run your application, e.g.

java -Xmx1024m YourClass

for allocating 1024 MB

java -Xmx2g YourClass

for allocating 2 GB

Edit: In regard to your note the java command is probably inside the .bat file. So you should open it up, find the java command and add the commandline arguments there.

dudel
  • 684
  • 5
  • 15
  • Thanks for the reply. – user28664 Oct 18 '16 at 13:16
  • Thanks for the reply, – user28664 Oct 18 '16 at 13:16
  • Thanks for the reply. I opened up command prompt and typed the code you suggested: java -Xmx2g MyApplication.bat. It did not seem to work. Am I doing something wrong? – user28664 Oct 18 '16 at 13:17
  • Since it is a .bat file the java command is probably inside the .bat file. Have a look in the file and there should be a command starting with java. There you can add the parameter. – dudel Oct 18 '16 at 13:20
  • I opened up the .bat file and entered following code: – user28664 Oct 18 '16 at 13:24
  • (java -cp quanta.jar;evol_engine.jar;jdom.jar;jakarta-poi.jar net.ndmystko.qa.QA SCK 2> error.log java -Xmx2g) It still does not seem to work. What am I doing wrong? – user28664 Oct 18 '16 at 13:25
  • Just put the -Xmx2g after the initial `java` at the beginning of the line, e.g. `java -Xmx2g -cp ...` – dudel Oct 18 '16 at 13:28
  • Now the application does not run anymore. Do I need to add anything after the -Xmx2g? – user28664 Oct 18 '16 at 13:31
  • If you just take the original command and add -Xmx2g after the initial java command it should look like the following: `java -Xmx2g -cp quanta.jar;evol_engine.jar;jdom.jar;jakarta-poi.jar net.ndmystko.qa.QA SCK 2> error.log`. If it does not start there should be an error message. Have a look in the error log. Alternatively you can also remove `2> error.log` and add a pause command below the java command and execute the .bat. This will leave the commandline window open after the program terminates. – dudel Oct 18 '16 at 13:36
  • The bat file looks like the following: java -Xmx2g -cp quanta.jar;evol_engine.jar;jdom.jar;jakarta-poi.jar net.ndmystko.qa.QA SCK 2> error.log. When I run it, a prompt flashes quickly and nothing happens after. The error.log file remains empty. – user28664 Oct 18 '16 at 13:40
  • If you put `pause` below the java command the prompt should stay open and there should be some kind of message. – dudel Oct 18 '16 at 13:44
  • The prompt reads: Error occurred during initialization of VM. Could not reserve enough space for 2097152KB object heap – user28664 Oct 18 '16 at 13:46
  • Then it seems that you have not enough memory =). Try with e.g. 1024m. – dudel Oct 18 '16 at 13:49
  • That seems to do the trick! Strange, considering I have 8g of RAM. Thanks for all the help! – user28664 Oct 18 '16 at 13:52
  • No problem. I guess you are using a 32-bit JRE and with that you cannot allocate more than about 1.5GB. So if you want to allocate more memory you have to install a 64-bit JRE. – dudel Oct 18 '16 at 13:56