2018. 7. 18. 10:25
쓰레드 관련
2018. 7. 18. 10:25 in 팁&테크/Coldfusion
쓰레드가 실행중인 페이지 목록
<!--- Create the thread object --->
<cfobject type="JAVA" action="Create" name="thread" class="java.lang.Thread">
<!--- Get all stack traces from the thread object --->
<cfset stackTrace = thread.getAllStackTraces()>
<!--- Convert the entrySet into an array --->
<cfset stackArray = stackTrace.entrySet().toArray()>
<cfoutput>
<!--- Loop over the entrySet array --->
<cfloop from="1" to="#ArrayLen(stackArray)#" index="sIndex">
<!--- Get the current thread values --->
<cfset thisThread = stackArray[sIndex].getValue()>
<!--- Loop over current thread values --->
<cfloop from="1" to="#ArrayLen(thisThread)#" index="tIndex">
<!--- Get the filename for this thread --->
<cfset thisThreadFile = thisThread[tIndex].getFileName()>
<!--- If the file name contains .cfm output it --->
<cfif isDefined("thisThreadFile") AND (thisThreadFile CONTAINS ".cfm" OR thisThreadFile CONTAINS ".cfc")>
#thisThreadFile#<br>
</cfif>
</cfloop>
</cfloop>
</cfoutput>
Coldfusion admin tool을 사용한 쓰레드 목록 및 쓰레드 중지
<cfscript>
function getActiveThreadsRunning(adminPassword) hint="Get all active threads running currently" {
var threadArrray = arrayNew(1);
//Creating Admin Object
var adminObject = createobject("component","cfide.adminapi.administrator");
//Creating Server Monitoring Object
var monitorObject = createobject("component","cfide.adminapi.servermonitoring");
//Login to Admin API
adminObject.login(arguments.adminPassword);
//Get all Active Thread info
threadArrray = monitorObject.getAllActiveCFThreads();
//log out from the admin API login
adminObject.logout();
return threadArrray;
}
function killActiveThread(adminPassword, threadName) hint="Kill specified thread which are running" {
//Creating Admin Object
var adminObject = createobject("component","cfide.adminapi.administrator");
//Creating Serbver Monitoring Object
var monitorObject = createobject("component","cfide.adminapi.servermonitoring");
//Login to Admin API
adminObject.login(arguments.adminPassword);
//kill thread now by calling abortCFThread. It accepts thread name
var killedThread = monitorObject.abortCFThread(arguments.threadName);
//logout from admin API
adminObject.logout();
// return true/false based on response.
return killedThread;
}
</cfscript>