CFLib.org – Common Function Library Project

amInCFThread()

Last updated April 11, 2008

author

Mark Mandel

Version: 1 | Requires: CF8 | Library: UtilityLib

Description:
Allows for the checking of executing code is being run inside a cfthread block or not.

Return Values:
Returns a boolean.

Example:

<cfscript>
	//get the response writer, so we can write to the HTTP Stream 
	//from within a cfthread call
	out = getPageContext().getResponse().getWriter();

	out.write("on cfthread: " & amInCFThread());
</cfscript>

<hr>
<cfthread action="run" name="test">
	<cfscript>
		out.write("on cfthread: " & amInCFThread());
	</cfscript>
</cfthread>

Parameters:

No arguments.

Full UDF Source:

<!---
 returns 'true' if the currentthread is a cfthread, rerturns false otherwise
 
 @return Returns a boolean. 
 @author Mark Mandel (mark@compoundtheory.com) 
 @version 1, April 11, 2008 
--->
<cffunction name="amInCFThread" hint="returns 'true' if the current thread if a cfthread, rerturns false otherwise" access="public" returntype="boolean" output="false">
	<cfscript>
		var Thread = createObject("java", "java.lang.Thread");

		if(Thread.currentThread().getThreadGroup().getName() eq "cfthread")
		{
			return true;
		}

		return false;
	</cfscript>
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson