CFLib.org – Common Function Library Project

amInCFThread()

Last updated April 11, 2008

Version: 1 | Requires: ColdFusion 8 | Library: UtilityLib

 
Rated 1 time(s). Average Rating: 4.0

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

Return Values:
Returns a boolean.

Example:

view plain print about
<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:

view plain print about
<!---
 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

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
29 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson