avoid coldfusion hang |
Ketan Jetty
enthusiasm for technology
|
||
functions
|
|||
|
avoid coldfusion hang Note: 1. Create a file. eg. C:/temp/test.csv 2. populate this file with say million lines of sample data. eg. test 3. run the above script 4. you will notice coldfusion eating up the entire JVM memory This is potential pitfall most programmer fail to realise and force reboot cf servers. Why does this happen? Coldfusion is build as a layer on top of Java, coldfusion assumes the process to be a single request and does not release the old query objects.
How to avoid a coldfusion hang
<cfscript>
fileReader = createObject("java", "java.io.FileReader").init("c:/temp/test.csv");
bufferedReader = createObject("java", "java.io.BufferedReader").init(fileReader);
try
{ curLine = '';
do
{ curLine = bufferedReader.readLine();
curLineCheck = IsDefined("curLine");
if (curLineCheck) {
insertData(curLine);
}
} while(curLineCheck);
} catch (Exception e) {
// this indicates end of file, ok to ignore error
}
bufferedReader.close();
fileReader.close();
</cfscript>
<cffunction name="insertData" returntype="void">
<cfargument name="line" type="String" required="true">
<cfquery name="test" datasource="dsnCF">
insert into someTable (col) values ('#line#')
</cfquery>
</cffunction>
|
|
||
| Ketan Jetty @ 2010. All Rights Reserved. | |||