I am getting JVM crash issue frequently while trying to write to the Excel file.I am using Apache POI 3.12 and Java 8 and Tomcat Server. I get the following hs_err_pid error:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGBUS (0x7) at pc=0x00007f16e02d1ec0, pid=1135, tid=0x00007f1595ef8700
#
# JRE version: OpenJDK Runtime Environment (8.0_352-b08) (build 1.8.0_352-8u352-ga-1~18.04-b08)
# Java VM: OpenJDK 64-Bit Server VM (25.352-b08 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libzip.so+0x4ec0]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
------
Stack: [0x00007f1595df8000,0x00007f1595ef9000], sp=0x00007f1595ef5900, free space=1014k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libzip.so+0x4ec0]
C [libzip.so+0x5b6e]
C [libzip.so+0x3b25] Java_java_util_zip_ZipFile_getEntry+0x85
J 91 java.util.zip.ZipFile.getEntry(J[BZ)J (0 bytes) @ 0x00007f16cd13ea8e [0x00007f16cd13e9c0+0xce]
J 123871 C2 java.util.zip.ZipFile.getInputStream(Ljava/util/zip/ZipEntry;)Ljava/io/InputStream; (304 bytes) @ 0x00007f16d6716944 [0x00007f16d67165c0+0x384]
J 124037 C2 org.apache.poi.openxml4j.opc.PackagePart.getInputStream()Ljava/io/InputStream; (44 bytes) @ 0x00007f16cda4bd00 [0x00007f16cda4bc60+0xa0]
J 103326 C1 org.apache.poi.POIXMLProperties.<init>(Lorg/apache/poi/openxml4j/opc/OPCPackage;)V (212 bytes) @ 0x00007f16d6af7374 [0x00007f16d6af6300+0x1074]
J 100022 C1 org.apache.poi.POIXMLDocument.getProperties()Lorg/apache/poi/POIXMLProperties; (40 bytes) @ 0x00007f16cd79ddfc [0x00007f16cd79dce0+0x11c]
J 67174 C1 org.apache.poi.POIXMLDocument.write(Ljava/io/OutputStream;)V (35 bytes) @ 0x00007f16cd89404c [0x00007f16cd893a80+0x5cc]
J 65014 C1 com.bulk.helper.ExcelUtility.saveWorkBook(Lorg/apache/poi/ss/usermodel/Workbook;Ljava/lang/String;Ljava/lang/String;)V (89 bytes) @ 0x00007f16cd543754 [0x00007f16cd542ea0+0x8b4]
J 71211 C1 com.bulk.helper.ExcelAccess.save_userfile(Ljava/lang/String;Ljava/lang/String;)V (14 bytes) @ 0x00007f16ce6e46ec [0x00007f16ce6e4640+0xac]
J 93237 C1
The following is the code:
Calling class:
accessFile.save_newFile(---);
Common Method Class:
@Override
public void save_userfile(String filePath , String fileName) {
utility.saveWorkBook(userWorkbook,filePath,fileName);
}
public void saveWorkBook(Workbook workbook ,String filePath, String fileName){
try
{
File directory = new File(filePath);
if (!directory.exists()) {
directory.mkdir();
}
File file = new File(directory,fileName);
OutputStream out = new FileOutputStream(file);
workbook.write(out);
out.flush();
out.close();
workbook.close();
}catch(Exception e){
LOG.error(Constants.ERROR_STRING,e);
}
}
I am aware of the solution of putting "-Dsun.zip.disableMemoryMapping=true" parameter.
Enabling this option will impact performance because the VM will have to conduct some additional disk IO every time it reads an entry from a JAR file (to interrogate the central directory structure).
Want to solve this issue programmatically in java 8 itself.
Any help will be appreciated,Thanks in advance..