Wednesday, April 9, 2008

Simplified locking_11

Because ColdFusion MX is now built on Java, you no longer need to worry about data corruption

in the shared memory scopes: Session, Application, and Server. Unfortunately, this fact has been misinterpreted by some to mean

"Hey—I don't need to lock my Session variables anymore!" Nothing can be farther from the

truth.

You still need to lock shared memory scopes to prevent what are known as race conditions,

where one piece of code may interfere with another that is also trying to access the same

data in shared memory. Race conditions are more prevalent than you may think; all in all,

you're most likely to continue to lock shared memory scopes almost as much as you did in

earlier versions of ColdFusion.

The new locking rules do enable you to safely read and write "write-once" variables in shared

memory scopes without locking. So if you have a Session variable that is created only once

during a session, is never destroyed and recreated, is never modified under any conditions

whatsoever, and is never CFSET a second time—even with the same value that it had previously—

you do not need to lock access to it.

0 comments: