Skip to main content
Participant
May 13, 2008
Question

Problem with application-variables - CFLOCK?

  • May 13, 2008
  • 3 replies
  • 671 views
Hi,

i have a problem with my application. It is a multi-user application with 100 parallel-users and CFMX 7.

The problem wich occures is with application variables. These are mainly structs wich get filled onApplicationStart(). The problem is, that the variables suddenly disappear, they are empty.

I have read about CFLock and found out, that it is necesseary to use cflock. And i found out, that onApplicationStart does correct locking automatically. That is where i do not understand the problem. The variables get intialized correctly and in further they only get read-access. Why can they be corrupted?

My other question about that is, wheather i need cflock for all Read-Access to Application and Session-Variables, even if there happens no writing to the variables?

Best Regards,
Andreas
    This topic has been closed for replies.

    3 replies

    Inspiring
    May 15, 2008
    > >>Also, you should be VARing all the variables you use local to a function,

    >
    > what is a local function ?

    The variable is local, not the function ;-)

    Read this -
    http://livedocs.adobe.com/coldfusion/8/htmldocs/buildingComponents_29.html
    - esp the last section on the VAR keyword.

    --
    Adam
    SpaCargoAuthor
    Participant
    May 15, 2008
    Thanks for your Help !

    this part of code seems to be a problem. Maybe this is the reason, why the struct sometimes crashes. This problem is really strange, cause it does not occure always. There are a lot of days, without this problem. I will fix this and hope the problem is solved.

    >>Also, you should be VARing all the variables you use local to a function,
    btw.

    what is a local function ?

    Greetings and thanks for your help,
    Andreas
    Inspiring
    May 13, 2008
    Without seeing any of your code, it's a bit hard to make an informed
    comment on much of this.

    Post your onApplicationStart() method, and perhaps any other code in the
    app that has the application variables on the left-hand-side of any
    assignment expressions.

    If your shared-scope usage is simple

    <cfset application.x = y>

    Then there's unlikely to be a need to lock it.

    If, however, the expression is more like:

    <cfset application.x = someLongRunningMethod()>

    Or if the code that creates the application-scoped variable is
    self-referential and is spread over multiple statements, then you might
    need to lock the assignment operation to prevent "race conditions" (google
    it).

    --
    Adam
    SpaCargoAuthor
    Participant
    May 13, 2008
    Hi Adam,

    thanks for your answer and help.

    My Application.cfc looks like this:

    <cffunction name="onApplicationStart" returntype="void">
    <cfscript>
    Application.DSN="cargorent";
    Application.DBT="Oracle80";
    // create the translation object
    Application.oTrans = createObject( "component", "cargorent.cfc.crtranslate" );
    Application.oTrans.init();
    // create the PopUp Object
    Application.oPopUp = createObject( "component", "cargorent.cfc.crPopUp" );
    </cfscript>
    <cfinclude template="Login/computer_setting/setting.cfm">
    <cfinclude template="Login/IniValues.cfm">
    <cfinclude template="Login/Version.cfm"><!--- This includes the Version information --->
    <cfinclude template="Login/Lists.cfm">
    </cffunction>


    the "problem-code" is in Lists.cfm. In this CFM, nearly 20 querys will be executed and afterwards converted into structs. This is done like this:


    // --- Code from Lists.cfm --- Called by onApplicationStart()
    <cfquery name="qToStatus" datasource="#Application.DSN#" dbtype="#Application.DBT#">
    SELECT td_text, td_internal_text FROM textual_definition
    WHERE td_type = 'TOUR_STATUS' ORDER BY td_key1
    </cfquery>
    <cfscript>
    application.TourStatus = ArrayNew(1);
    for( i=1; i lte qToStatus.RecordCount; i=i+1 )
    {
    application.TourStatus = StructNew();
    application.TourStatus
    .text = qToStatus.TD_TEXT ;
    application.TourStatus
    .value = qToStatus.TD_INTERNAL_TEXT ;
    }
    </cfscript>