Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created September 23, 2021 11:39
CFThread "ElapsedTime" Is Not "Processor Time" In Lucee CFML 5.3.8.201
<cfscript>
thread name = "one" {
sleep( 500 );
thread.lastLineAt = now().timeFormat( "hh:nn:ss" );
}
thread name = "two" {
sleep( 2500 );
thread.lastLineAt = now().timeFormat( "hh:nn:ss" );
}
thread name = "three" {
sleep( 4500 );
thread.lastLineAt = now().timeFormat( "hh:nn:ss" );
}
// Wait for all threads to complete and then check status.
thread action = "join";
cfdump( var = cfthread.one, show = "Name,ElapsedTime,StartTime,LastLineAt" );
cfdump( var = cfthread.two, show = "Name,ElapsedTime,StartTime,LastLineAt" );
cfdump( var = cfthread.three, show = "Name,ElapsedTime,StartTime,LastLineAt" );
// Sleep another few seconds and the re-check the status.
sleep( 2000 );
writeOutput( "<hr />" );
cfdump( var = cfthread.one, show = "Name,ElapsedTime,StartTime,LastLineAt" );
cfdump( var = cfthread.two, show = "Name,ElapsedTime,StartTime,LastLineAt" );
cfdump( var = cfthread.three, show = "Name,ElapsedTime,StartTime,LastLineAt" );
</cfscript>
<cfscript>
thread name = "one" {
sleep( 500 );
thread.lastLineAt = now().timeFormat( "hh:nn:ss" );
}
thread name = "two" {
sleep( 2500 );
thread.lastLineAt = now().timeFormat( "hh:nn:ss" );
}
thread name = "three" {
sleep( 4500 );
thread.lastLineAt = now().timeFormat( "hh:nn:ss" );
}
// Wait for all threads to complete and then check status.
thread action = "join";
dump( var = cfthread.one, show = "Name,ElapsedTime,StartTime,LastLineAt" );
dump( var = cfthread.two, show = "Name,ElapsedTime,StartTime,LastLineAt" );
dump( var = cfthread.three, show = "Name,ElapsedTime,StartTime,LastLineAt" );
// Sleep another few seconds and the re-check the status.
sleep( 2000 );
echo( "<hr />" );
dump( var = cfthread.one, show = "Name,ElapsedTime,StartTime,LastLineAt" );
dump( var = cfthread.two, show = "Name,ElapsedTime,StartTime,LastLineAt" );
dump( var = cfthread.three, show = "Name,ElapsedTime,StartTime,LastLineAt" );
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment