Brian Ferrigno said:
> the code does work by creating a deadlock for the session
Deadlock, not race condition. Quite right. Too many Krispy Kremes for me.
Point being, it blocks and *does not* spike your processor or anything lame
like that. The only downside is that it blocks all other locks for that
session. Of course, if you're using this for automated tasks, that's not
really a problem.
> But does this effect only this one user session?
Yes. Session-level locking only affects that particular session. If you
want to block everything to that page, you could use Application-level
locking. (But that would block all the locks in the entire application!)
> And does anyone know what the maximum TIMEOUT value can be
> for this cflock tag? or what is safe?
I've never read anything about maximum or safe values in relation to the
tag. I would imagine that as long as you don't exceed your RequestTimeout
parameter, you should be okay.
I've attached code that illustrates the point. Both pages will lock for
just about 5 seconds, even though only one of them has the deadlock code.
The other blocks while trying to get a read-only lock. This works on my
Intranet where the browser requests for the two sub-pages are essentially
simultaneous, but if you're doing this over the Internet you may have to
mess with it a bit.
-R
<CFSWITCH EXPRESSION="#CGI.QUERY_STRING#">
<CFCASE VALUE="1">
<CFSET Start=GetTickCount()>
<CFLOCK SCOPE="SESSION" TIMEOUT="10" TYPE="READONLY">
</CFLOCK>
<CFSET End=GetTickCount()>
<CFSET Elapsed=End-Start>
<CFOUTPUT>Elapsed: #Elapsed#ms</CFOUTPUT>
</CFCASE>
<CFCASE VALUE="2">
<CFSET Start=GetTickCount()>
<CFTRY>
<CFLOCK SCOPE="SESSION" TIMEOUT="5" TYPE="READONLY">
<CFLOCK SCOPE="SESSION" TIMEOUT="5" TYPE="EXCLUSIVE">
</CFLOCK>
</CFLOCK>
<CFCATCH></CFCATCH>
</CFTRY>
<CFSET End=GetTickCount()>
<CFSET Elapsed=End-Start>
<CFOUTPUT>Elapsed: #Elapsed#ms</CFOUTPUT>
</CFCASE>
<CFDEFAULTCASE>
<CFOUTPUT>
<HTML>
<FRAMESET ROWS="50%,50%">
<FRAME SRC="#CGI.SCRIPT_NAME#?1">
<FRAME SRC="#CGI.SCRIPT_NAME#?2">
</FRAMESET>
</HTML>
</CFOUTPUT>
</CFDEFAULTCASE>
</CFSWITCH>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists