temp imageio files in Tomcat gnerated by botBinFormat ?

User 55ffa2f197

25-07-2013 21:34:17

Hi I am using following simple jsp script to generate mol image from tomcat server. I am sending in valid Mol and format as parameter. However i have noticed that there are imageio files generated when running this webapp, the temp image file got written into CATALINA_TEMPDIR as defined in Tomcat env file. My Tomcat setting is the default setting, i did not do any customization. The temp dir is : /apps/ibmapp/apache-tomcat-7.0.39/temp, the temp file has the name like : imageio7267496980310869538.tmp.


Can you take a look at my script, see if we can figure out where the temp files come from. Once the number of the temp files reach ~3000, Tomcat will hang giving an error of "Too many open files ...." . Though i can delete the temp files while the server is running, but the files, marked as deleted still being considered by Tomcat as open. So once that happens i have to stop and restart the server, this is quite annoying.


Thanks for your help


Dong


Here is the script:


<%@page import="java.io.*,
java.net.URLDecoder,
chemaxon.formats.MolImporter,
chemaxon.struc.Molecule"%>
<%
ServletOutputStream outs = null;
try {
    // Retrieving GET/POST parameters
    String format = request.getParameter("format");
    String molstring = null;
    molstring = request.getParameter("mol");
    String type = format.indexOf(":") == -1 ?  format : format.substring(0, format.indexOf(":"));
    response.setContentType("image/" + type);
    Molecule mol = null;
    mol = MolImporter.importMol(molstring);
    byte[] b = mol.toBinFormat(format);
    outs = response.getOutputStream();
    //out.clear();
    //out = pageContext.pushBody();
    outs.write(b,0,b.length);
    outs.flush();
} catch(Throwable t) {
        t.printStackTrace();
} finally {
        try{
           outs.close();
        }catch (Exception inner){
        }
}
%>

User 55ffa2f197

26-07-2013 12:05:23

I googled this "imageio tmp files" and found the first response as this "https://www.chemaxon.com/forum/ftopic8554.html". In it Istvan described the fix, i changed my code as following and the temp file(s) will not be generated, so my app is OK, does not need baby sitting.


I copied my original code from ChemAxon tutorial and i hope you guys update your code, we should make simple thing bullete proof, so we have time to do better thing.


Thanks


Dong.


The script did not produce tmp file and no catalina error:


<%@page import="
java.io.*,
java.net.URLDecoder,
javax.imageio.ImageIO,
chemaxon.formats.MolImporter,
chemaxon.struc.Molecule"%>
<%
ServletOutputStream outs = null;
ImageIO.setUseCache(false);
try {
    // Retrieving GET/POST parameters
    String format = request.getParameter("format");
    String molstring = null;
    molstring = request.getParameter("mol");
    String type = format.indexOf(":") == -1 ?  format : format.substring(0, format.indexOf(":"));
    response.setContentType("image/" + type);
    Molecule mol = null;
    mol = MolImporter.importMol(molstring);
    byte[] b = mol.toBinFormat(format);
    outs = response.getOutputStream();
    out.clear();
    out = pageContext.pushBody();
    outs.write(b,0,b.length);
    outs.flush();
} catch(Throwable t) {
        t.printStackTrace();
} finally {
        try{
           outs.close();
        }catch (Exception inner){
        }
}
%>

ChemAxon 5433b8e56b

26-07-2013 15:41:29

Hi Dong,


first I was thought it is falling back to this issue: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4894964 but then realized that we are calling the close on all used ImageInputStream and ImageOutputStream.


So I fallow up with this issue, and found this issue: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4171239 which duplicates this one: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6357433 the last one is not fixed currently.


From the second one it seems that the javax.imageio if it use file cache, then it marks the files created with the deleteOnExit flag. But as I assume, the tomcat instance is not exiting, and therfore the files are not deleted.


You can call the javax.imageio.ImageIO.setUseCache(false) method call somewhere in the service initialization, to omit the disk based caching inside image streams created by the imageio classes.


I hope this helps.


Regards,
Istvan