Skip to content

Instantly share code, notes, and snippets.

@l-brett l-brett/threads.cfm
Created Feb 11, 2019

Embed
What would you like to do?
Coldfusion - Get a list of all current threads
<!--- Create the thread object --->
<cfobject type="JAVA" action="Create" name="thread" class="java.lang.Thread">
<!--- Get all stack traces from the thread object --->
<cfset stackTraces = thread.getAllStackTraces()>
<!--- Convert the keySet to an array --->
<cfset keys = stackTraces.keySet().toArray()>
<style>
.text {
padding: 1em;
color:white;
background:black;
margin: 1em;
}
</style>
<p>Number of threads: <cfoutput>#ArrayLen(keys)#</cfoutput>
<cfoutput>
<!--- Loop over the keys array --->
<cfloop from="1" to="#ArrayLen(keys)#" index="sIndex">
<!--- Get the current thread --->
<cfset thisThread = keys[sIndex]>
<!--- Output the current thread name --->
<p class="text"><cfdump var="#thisThread.getName()#" /></p>
</cfloop>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.