User Guide Cancel

InterruptThread

 

Description

Interrupts given thread. When interrupt is called on a thread it sets interrupt status flag on CFThread. If a thread is blocked in an invocation of the ThreadJoin or sleep method, then its interrupt status will be cleared, and it will receive an InterruptedException. Interrupting a thread that is not alive need not have any effect.

Returns

None

Syntax

interruptThread()
interruptThread(threadName)
interruptThread() interruptThread(threadName)
interruptThread()

interruptThread(threadName)

Parameters

  • threadName: (Optional) Name of the thread to interrupt. If you do not provide the thread name, the current thread will be interrupted.

History

  • ColdFusion (2025 release): Added the function.

Example

code

<cfscript>
testThreadName = "interrupt-self"
thread action="run" name="#testThreadName#" {
variables.message = "before interrupt...<br>"
variables.message &= "isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>"
interruptThread();
variables.message &= "after interrupt...<br>"
variables.message &= "isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>"
}
thread action="join" name="#testThreadName#"{}
writeOutput(variables.message)
writeOutput("isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>")
</cfscript>
<cfscript> testThreadName = "interrupt-self" thread action="run" name="#testThreadName#" { variables.message = "before interrupt...<br>" variables.message &= "isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>" interruptThread(); variables.message &= "after interrupt...<br>" variables.message &= "isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>" } thread action="join" name="#testThreadName#"{} writeOutput(variables.message) writeOutput("isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>") </cfscript>
<cfscript>
        testThreadName = "interrupt-self"

        thread action="run" name="#testThreadName#" {
            variables.message = "before interrupt...<br>"
            variables.message &= "isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>"
            interruptThread();
            variables.message &= "after interrupt...<br>"
            variables.message &= "isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>"
            
        } 
        thread action="join" name="#testThreadName#"{}
        writeOutput(variables.message)
        writeOutput("isInterrupted:" & isThreadInterrupted(testThreadName) & "<br>")
</cfscript>

Output

before interrupt...
isInterrupted:NO
after interrupt...
isInterrupted:YES
isInterrupted:YES

Get help faster and easier

New user?