Java应用程序和tomcat在没有明显原因的情况下突然停止

Java应用程序和tomcat在没有明显原因的情况下突然停止,java,tomcat,memory-leaks,jvm,heap-memory,Java,Tomcat,Memory Leaks,Jvm,Heap Memory,我正在使用Jpedal工具将PDF转换为图像。Jpedal工具帮助将任意或大量PDF页面(假设PDF页面=1200)转换为.PNG图像。一般来说,这是可行的,但是在将大量PDF页面转换为图像的过程中,偶尔会导致应用程序和tomcat在没有任何信息或日志的情况下停止 似乎这只是一个未打印的OutOfMemory错误。在处理过程中,它打印行logger.info(“宽度=“+width+”高度=“+height”)多次,但在某一点之后退出并停止tomcat。 谁能帮我做同样的事情吗。 我的密码:-

我正在使用Jpedal工具将PDF转换为图像。Jpedal工具帮助将任意或大量PDF页面(假设PDF页面=1200)转换为.PNG图像。一般来说,这是可行的,但是在将大量PDF页面转换为图像的过程中,偶尔会导致应用程序和tomcat在没有任何信息或日志的情况下停止

似乎这只是一个未打印的OutOfMemory错误。在处理过程中,它打印行logger.info(“宽度=“+width+”高度=“+height”)多次,但在某一点之后退出并停止tomcat。 谁能帮我做同样的事情吗。 我的密码:-

public boolean createPDF2ImageTask(String sourcePDFAbsPath, String destinationImageAbsPath, Float scalingFactor, String fileFormat, int softLimitInKB) throws Exception
{ 

System.setProperty("org.jpedal.flattenForm","true");
logger.info("createPDF2ImageTask ( sourcePDFAbsPath = "+sourcePDFAbsPath+" , destinationImageAbsPath = "+destinationImageAbsPath+ ", scalingFactor = "+scalingFactor+ " , fileFormat = "+fileFormat+ " softLimitInKB ="+softLimitInKB );
boolean status = true;
Float newScalingFactor;
int sizeOfImageInKB;

//PdfDecoder object provides the conversion 

PdfDecoderServer decoder = null;
Map mapValues = null;
BufferedImage imageToSave = null;
BufferedOutputStream bufferedOutputStream = null;
long startTime = System.currentTimeMillis();
try
{

    Helper.deleteFile(destinationImageAbsPath);

    //mappings for non-embedded fonts to use
    FontMappings.setFontReplacements();

    decoder = new PdfDecoderServer(true);
    decoder.openPdfFile(sourcePDFAbsPath);


    mapValues = new HashMap();


    mapValues.put(JPedalSettings.EXTRACT_AT_BEST_QUALITY_MAXSCALING, 2);

    //alternatively secify a page size (aspect ratio preserved so will do best fit)
    //set a page size (JPedal will put best fit to this)
    PdfPageData pageData = decoder.getPdfPageData();
    int width = (int)(scalingFactor*pageData.getCropBoxWidth(1));
    int height = (int)(scalingFactor*pageData.getCropBoxHeight(1));
    logger.info("width = "+ width + "   height= "+height);          
    mapValues.put(JPedalSettings.EXTRACT_AT_PAGE_SIZE, new String[]{String.valueOf(width),String.valueOf(height)});

    //which takes priority (default is false)
    mapValues.put(JPedalSettings.PAGE_SIZE_OVERRIDES_IMAGE, Boolean.TRUE);

    PdfDecoderServer.modifyJPedalParameters(mapValues);                              

    /////////////////////////////////////////////////////////////////////////////////////

    try
    {
        imageToSave = decoder.getPageAsHiRes(1, null, false);
        decoder.flushObjectValues(true);
        if(imageToSave != null)
        {
            logger.info("Start saving image as a file");
            bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(destinationImageAbsPath)));

            ImageIO.write(imageToSave, fileFormat, bufferedOutputStream);

        }
        else
        {
            throw new Exception("imageToSave is null, Exception in extractPageAsImage ");
        }
    }
    catch(Exception e)
    {
        logger.error("Exception in extractPageAsImage :: "+e);
        logger.error("Exception stack trace in extractPageAsImage :: ",e);
        throw new Exception("Exception in extractPageAsImage :: "+e);
    }

根据您提供的信息,内存不足错误似乎是一个大胆的猜测。您的理论依据是什么?@loonytune偶尔,应用程序可能会在本机堆分配失败后很快崩溃。如果运行的本机代码没有检查内存分配函数返回的错误,则会发生这种情况。例如,如果没有可用内存,malloc系统调用将返回NULL。如果未检查malloc的返回,则应用程序在尝试访问无效内存位置时可能会崩溃。根据不同的情况,这类问题可能很难找到。此外,这类问题仅适用于大文件,我读了一篇文章,文章中说,这个错误要么立即发生在大文件上,然后您可以进一步增加内存,要么调查一个文件为什么需要这么多内存。好的,这是真的。但在本例中,您将分配到本机内存中,这与JVM无关,因此您不可能在Java代码中检查或防范这种情况。但在这种情况下,也可能只是一个无效的指针解引用。在本机代码中,大量的事情可能会使您崩溃。尽管如此,尽管我不能排除这种可能性,但我看到“特殊迹象”表明这可能是内存问题,特别是如果您将本机代码引入其中…@loonytune:我看到这可能是内存问题。也许我们可以通过增加Tomcat实例的内存来解决这个问题。