User Guide Cancel

isThreadInterrupted

 

Description

Checks whether a thread has been interrupted. The interrupted status of the thread is unaffected by this method. A thread interruption ignored because a thread was not alive at the time of the interrupt will be reflected by this method returning false. This method has an equivalent method ThreadInterrupted, which checks if a current thread is interrupted.

Returns

True if a thread is interrupted.

Syntax

isThreadInterrupted(threadName)

Parameters

  • threadName: Name of the thread to interrupt.

History

  • ColdFusion (2025 release): Added the function.

Example

code

<cfscript>
testThreadName = "thread-interrupted"
thread action="run" name="#testThreadName#" {
count = 0;
while(!isThreadInterrupted(testThreadName)){
variables.message = count++;
writeOutput("thread #testThreadName# running.<br>");
}
writeOutput("Thread #testThreadName# interrupted. exiting.<br>");
}
sleep(2) //let the thread above startup.
writeOutput("isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>") //expect: no
interruptThread(testThreadName);
writeOutput("after interrupt, isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>") //expect: yes
</cfscript>
<cfscript> testThreadName = "thread-interrupted" thread action="run" name="#testThreadName#" { count = 0; while(!isThreadInterrupted(testThreadName)){ variables.message = count++; writeOutput("thread #testThreadName# running.<br>"); } writeOutput("Thread #testThreadName# interrupted. exiting.<br>"); } sleep(2) //let the thread above startup. writeOutput("isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>") //expect: no interruptThread(testThreadName); writeOutput("after interrupt, isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>") //expect: yes </cfscript>
<cfscript>
        testThreadName = "thread-interrupted"
        thread action="run" name="#testThreadName#" {
            count = 0;
            while(!isThreadInterrupted(testThreadName)){
                variables.message = count++;
                writeOutput("thread #testThreadName# running.<br>");
            }
            writeOutput("Thread #testThreadName# interrupted. exiting.<br>");
        }
        sleep(2) //let the thread above startup.
        writeOutput("isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>") //expect: no

        interruptThread(testThreadName);
        writeOutput("after interrupt, isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>") //expect: yes
</cfscript>

Output

isInterrupted:NO
after interrupt, isInterrupted:YES

Get help faster and easier

New user?