PDFファイルのディレクトリをループし、それぞれのサムネイルを作成するために使用している次の関数があります。
<cffunction name="createThumbnails" returntype="Void" output="false">
<cfscript>
// CONSTANTs
var _PDF_PATH = APPLICATION.PDFSource & "\PDFs";
// Set defaults for private variables
var _qPDFDir = QueryNew("");
var _documentId = 0;
var _sourceFilePath = "";
var _sku = "";
var _tempImageFilePath = "";
</cfscript>
<!--- Retrieve a list of file names in the directory of unprocessed PDF files --->
<cfdirectory
action="list"
directory="#_PDF_PATH#"
name="_qPDFDir"
filter="*.pdf"
type="file"
sort="datelastmodified DESC"
listinfo="name" />
<!--- Loop through the list of file names in the directory of unprocessed non-PDF files --->
<cfloop query="_qPDFDir" endrow="500">
<cfset _sourceFilePath = _PDF_PATH & "\" & name />
<cfif FileExists(_sourceFilePath) AND IsPDFFile(_sourceFilePath)>
<cftry>
<cfpdf
action="thumbnail"
source="#_sourceFilePath#"
destination="#APPLICATION.TempDir#"
format="png"
scale="100"
resolution="high"
overwrite="true"
pages="1" />
<cfcatch>
<cfscript>
FileMove(
_sourceFilePath,
_PDF_PATH & "\NonFunctioning\"
);
</cfscript>
</cfcatch>
</cftry>
<cfscript>
_documentId =
REQUEST.UDFLib.File.getFileNameWithoutExtension(name);
_tempImageFilePath =
APPLICATION.TempDir
& "\"
& _documentId
& "_page_1.png";
if (FileExists(_tempImageFilePath)) {
_sku = getSkuFromDocumentId(_documentId);
if (Len(_sku)) {
CreateObject(
"component",
"cfc.products.Product"
).setClientId(
getClientId()
).setId(
_sku
).createThumbnails(
sourcePath = _tempImageFilePath,
deleteSourceFile = true
);
FileMove(
_sourceFilePath,
APPLICATION.ProcessedPDFDir
);
}
}
</cfscript>
</cfif>
</cfloop>
<cfreturn />
</cffunction>
一部のコードは、私がやりたいことではありません。つまり、ファイルを「NonFunctioning」ディレクトリに移動しますが、ビジネス ルールで必要です。
私が理解しようとしているのは、この関数の実行時にメモリを使い果たすのをどのように回避できるかということです。
で、約148個のファイルを処理した後endrow="500"
、エラーで爆撃しました。java.lang.OutOfMemoryError: GC overhead limit exceeded
また、タスク マネージャー (Windows) で jrun.exe プロセスを監視すると、メモリがどんどん増えていくのがわかります。
この関数のパフォーマンスを改善して、メモリが食い尽くされるのを防ぐ方法はありますか?