Skip to content

Instantly share code, notes, and snippets.

@l-brett
Created February 11, 2019 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l-brett/5c766984bb7d9d993837b21031151827 to your computer and use it in GitHub Desktop.
Save l-brett/5c766984bb7d9d993837b21031151827 to your computer and use it in GitHub Desktop.
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