Workaround for handling expected java.lang.OutOfMemoryError: Java heap space

I am working on a Java Web Application based on Java 6 / Tomcat 6.0. This is a web based document management system. Customers can upload any files to this web application. After downloading the file, a new stream is created in which the downloaded file is analyzed. Analysis is performed using a third-party library.

These third-party libraries work fine in about 90% of analytical tasks, but sometimes (depending on the loaded file) the logic starts using all the remaining memory, which leads to OutOfMemoryError.

Since the whole application runs in one JVM, OoM-Error affects not only analytical tasks, but also affects other functions. In the worst case, the application crashes completely or remains in an inconsistent state.

Now I'm looking for a fairly quick (but safe) way to handle these OoM errors. Replacing the library is currently not an option (therefore, I did not mention the name of the library and did not do any analysis). Does anyone know what can be done to get around this error?

I was thinking of starting a new process (java.lang.ProcessBuilder) in order to have a new JVM. If third-party lib causes OoM-Error, this will not affect the web application. On the other hand, this will require additional efforts to synchronize the new Process with the analysis part of the web application. Does anyone have experience with such a system (especially regarding system stability)?

: 1) . . - -. . - , -lib . .

2) , OoM-Error. . , OoM-Error, ( 4 ). . JVM 256 , - OoM. JVM 512 . , - OoM.

3) ; , , 4 . . 32-, 64- (Windows Linux).

+4
2

, , -. :

  • , , ?
  • ?
  • ?

OOM.

, . , webapp - , -, . , , , , .

.

, JVM , ? JVM 32 64 , , , .

, , . , 32 64 , , , ..

, , , " ". , JEE. , . , , , , , ( ). , .

+2

(, ) lib, . (, ) . URL-, , , .

, . , .

+1

Source: https://habr.com/ru/post/1523534/


All Articles