Component in Application Scope and cflock

Hi,
I have an CFC that I set in application scope in the
onApplicationStart method which contains some system parameters,
one of which is a flag saying whether the site is currently
"Online". I call a method on this CFC in the Application.cfc
"onRequest" method to see if the flag value has changed.
This method looks up a parameter set in the database that
says whether the site is "online" or "offline". If the site is
currently online, I want to only redo the query every 5 mins.
However if the site is offline, I want to check more frequently
(every 5 secs) as to whether the flag has changed back.
What I am not sure of, is whether I need to be using
<cflock> when I change from "online" to "offline"? There is
only a single instance of this object, but what happens if multiple
requests are calling the "isSiteOnline" method simultaneously? Is
this "safe"?
Some code snippets are attached to illustrate.
Any advice would be greatly appreciated.
Regards,
Andrew.

> <!--- DO I NEED TO USE CFLOCK HERE???? --->
No, in either situation.
Ask yourself... what would the ramifications be of two
requests hitting
that line of code "simultaneously"? The end result is that
both of them
are setting the variable to the same static value... so
that's what's going
to end up happening: variables.instance.cacheInterval is
going to be set to
300 (or 5) in each situation.
You could well with to lock a block of code which - if called
simultaneously via more than one request - could act on
shared storage
space (server, application or session data) differently and
incorrectly
than is intended.
eg:
<!--- application bootstrap process --->
<cfif not structKeyExists(application, isInitialised and
not
application.isInitialised>
<!--- initialisation process, whatever it is --->
<cfif allOK>
<cfset application.isInitialised = true>
<cfelse>
<cfset application.isInitialised = false>
</cfif>
</cfif>
So a sequence of events could be (say the user is hitting the
site with two
different browsers):
REQUEST1: application.isInitialised doesn't exist
REQUEST1: starts the init process
REQUEST2: application.isInitialised STILL doesn't exist
REQUEST2: starts the init process *again*
REQUEST1: sets the application.isInitialised value
REQUEST2: sets the application.isInitialised value
Obviously one does not want two request running the
initialisation code.
note this is a slightly contrived example, as if one has an
OnApplicationStart() method, then it will only run once, and
that's where
one would have the init code, but it demonstrates the issue.
Google "race condition". Those are the situations in which
one needs to
lock blocks of code.
Adam

Similar Messages

  • Objects of application scope and clustering.

              I understand that weblogic 6.1 replicates session data to a secondary server in a
              cluster. This replication should include objects declared with <jsp:useBean ...
              scope="session"/> as well as objects that are explicitly maintained in the session
              with setAttribute().
              However, what about objects with application scope? Are they replicated to a secondary
              server when a cluster is in use?
              Thanks,
              -Dave.
              

    David Vazquez <[email protected]> wrote:
              > I understand that weblogic 6.1 replicates session data to a secondary server in a
              > cluster. This replication should include objects declared with <jsp:useBean ...
              > scope="session"/> as well as objects that are explicitly maintained in the session
              > with setAttribute().
              > However, what about objects with application scope? Are they replicated to a secondary
              > server when a cluster is in use?
              No, they are not replicated in the cluster. To implement replication you can use JavaGroups:
              http://sourceforge.net/projects/javagroups/ or Cameron's Coherence product:
              http://www.tangosol.com/products-clustering.jsp for example.
              > Thanks,
              > -Dave.
              Dimitri
              

  • Is that a good practice to use syncronize methods for application scope cls

    Is that a good practice to use synchronize method in a application scope class, so I have a doubt, there a is class A, it has application scope and it contains a synchronized method add, so because of some network traffic or any unexpected exception client1 got stuck in the method, will that add method available for any other client...?
    Edited by: navaneeth.j on Dec 17, 2009 4:02 AM
    Edited by: navaneeth.j on Dec 17, 2009 4:04 AM

    If it needs synchronization, then it probably doesn't belong in the application scope. Either keep it as is, or reconsider the scope, or make it static.

  • How can a session scope bean access an application scope bean - help

    Hello,
    I have a JSP page that has references to an Application Scope and a Session Scope bean...
    <jsp:useBean id="myWebApp" scope="application" class="com.my.web.WebApplication" />
    <jsp:useBean id="myWebSession" scope="session" class="com.my.web.WebSession" />
    I would like the WebSession access methods in the WebApplication ... Can/ How does the WebSession object lookup the reference to WebApplication object?

    I don't think you should make the WebSession implement the session listener.
    The session listener will be created once, at the start of the servlet context and would be listening to all sessions. So you would have one instance of the WebSession belonging to the context (though not as an attribute), and others belonging to each session. This will be confusing in your code, I think.
    I would suggest having a different class act as the HttpSessionListener. Perhaps do something like this:
    public class WebSessionInjector implements HttpSessionListener {
      public void  sessionCreated(HttpSessionEvent e) {
        WebApplication webApp = (WebApplication)(e.getSession().getServletContext().getAttribute("webapp"));
        WebSession mySession = new WebSession();
        mySession.setWebApplication(webApp);
        e.getSession().setAttribute("mySession", mySession);
      public void sessionDestroyed(HttpSessionEvent e) { ... }
    }You may be able to use the WebApplication object itself as the listener ...
    Or, you could make the WebSession implement the HttpSessionBindingListener and use the valueBound event much like the sessionCreated event above, but from inside the WebSession object:
    public class WebSession implements HttpSessionBindingListener {
      public void  valueBound(HttpSessionBindingEvent e) {
        WebApplication webApp = (WebApplication)(e.getSession().getServletContext().getAttribute("webapp"));
        this.setWebApplication(webApp);
      public void valueUnbound(HttpSessionBindingEvent e) { ... }
    }

  • What are the pros and cons of storing heavely used CFCs in the application scope?

    I've been storing all the required CFCs for a site in the application scope. During onApplicationStart I do something like this application.objSomeCfc =CreateObject('component', 'com.someCfc').init().
    Here is my reasoning.
    Get the CFCs initialized once and stored in memory for better performance.
    Using CreateObject several times on each page load can have a negative impact on performance.
    Having one place to create application scoped CFCs makes it easier to manage code.
    So is my thinking flawed? Are there any additional pros or cons for dealing with CFCs? Is there any docs, articles, blogs, videos, frameworks, ...... that I should check that may change my perspective on how I'm doing this?
    Thanks

    Your approach is fine, depending on how many and what type of CFCs you are talking about. If they are "singletons" - that is, only one instance of each CFC is needed to be in memory and can be reused/shared from multiple parts of your application - caching them in the application scope is common.  Just make sure they are thread safe ("var" or local.* all your method variables).
    You might consider taking advantage of a dependency injection framework, such as DI/1 (part of the FW/1 MVC framework), ColdSpring, or WireBox (a module of the ColdBox platform that can be used independently).  They have mechanisms for handling and caching singletons.  Then you wouldn't have to go to the application scope to get your CFC instances.
    -Carl V.

  • Application Scope Objects and Multithreading

    I will be creating a set of interlinking objects in application scope that are intended for read only. The objects will be accessed every time a user makes a request to the servlet which will be on every link of the site since the servlet is a controller.
    I am pretty sure that there are no concurrency issues here - that all requests will be able to access the objects quickly. Can someone confirm this for me.

    As long as the threads only read information from the objects and do not update them then you should be ok.

  • Creation of an Application Configuration and corresponding Component Config

    I try to create an application configuration , by going  to the object tree at the left hand side and do right click on the application object and select Create/Change Configuration
    but i get the following error text  : Screen output without connection to user.
    why ?
    any help

    Hi,
    i dont see this problem ever.
    Please check this Article to create Application configuration.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b52e13c3-0901-0010-8fa6-d11a51821b7c
    Thanks
    Suman
    Edited by: suman kumar chinnam on Sep 17, 2008 2:25 PM

  • Flash and cflock

    Running Coldfusion8
    Flex 3
    I am trying to do a cflock (either session or application) in a function.
    I get the error message:
    "Cannot use cflock to lock the application or session shared scopes without these scopes  being established through the use of the cfapplication tag. To use the session  scope you need to enable session management. Application and/or Session variables  must also be enabled in the ColdFusion Administrator."
      faultString = "Unable to invoke CFC - Cannot lock Application scope."
    Session management is enabled in both the administrator and Application.cfc.
    I am thinking that RemoteObject is not going though the "Application.cfc" and is
    just doing a direct call to the ColdFusion Component.
    How do I get thread-safe removeobject calls?
    Any ideas how to resolve this problem?

    Visit http://support.apple.com/kb/DL1399 and reinstall the update.
    Also please update your profile it indicates you are using:
    G4, MacBook Air, and Ipod Touch, Mac OS X (10.5.6) so it's kind of confusing.

  • 300 requests per hour reading from Application scope Good/Bad idea

    I am saving some html in application scope & reading with
    <cflock readonly.
    Will it be a problem if more than 5 requests are made per
    second?
    Does deadlocks occurs with readonly-cflock?
    Thanks

    While creating/changing application scope variables in a
    lock, I think there must be an exclusive lock. You must be careful
    not to set any shared variable such as application inside a read
    only cflock tag.
    I also would suggest to check the usage of Application.cfc
    and onApplicationStart method. You can set application default
    variables and constants in onApplicationStart method in your
    Application.cfc.

  • A struct in the application scope will be lost / damaged

    Hello,
    we have a strange problem with our CFMX 7,0,2, perhaps
    somebody can help?
    In the application.cfm a xml-file will be loaded, parsed and
    saved as a struct in an application variable. This will take place
    only if the struct isn't defined. We set the application variable
    exclusive by cflock. After some times, the struct or an element of
    the struct will be lost. At this time, we get "Null Pointer
    Exceptions".
    java.lang.NullPointerException
    at coldfusion.xml.XmlNodeMap.size(XmlNodeMap.java:656)
    at coldfusion.runtime.Struct.StructCount(Struct.java:172)
    at coldfusion.runtime.CFPage.StructCount(CFPage.java:4133)
    Some questions:
    - Why is the struct / the elements in the application scope
    are lost? The application timeout is set to 2days, and other
    application variables aren't lost.
    - Why will cftry / cfcatch not work in this case?
    What can we do?
    Kind regards
    Karl-Heinz

    you can use the isDefined function in the onRequestStart
    function in Application.cfc
    I have never had an application scoped variable / object get
    lost or damaged in the way that you're describing.
    are you loading it in the onApplicationStart function of
    Application.cfc ? that would be a good place to do it.
    oh, actually, I did have a contractor who assigned the
    application name dynamically, I think the name contained the
    current date so each time the date would change the application
    would change - you might want to make sure that is not happening to
    you.

  • Application.cfm and CFC's

    for some reason my cfc is not seeing any of the variables set
    in application.cfm. Furthermore it does not see them when I use
    application.cfc. I am running 6.1MX on iis5. Any info would be
    helpful.
    Thanks

    Duke Snyder wrote:
    > for some reason my cfc is not seeing any of the
    variables set in
    > application.cfm. Furthermore it does not see them when I
    use application.cfc. I
    > am running 6.1MX on iis5. Any info would be helpful.
    >
    > Thanks
    >
    In deference to Adam, I'm going to go ahead an make a guess.
    Directory structure is very important here. Application.cfm
    will only
    apply to code that is run in the same directory or any sub
    directory
    there under. This applies to CFC's as well. A common idea is
    to place
    a CFC in some type of common folder that is outside the
    normal
    application structure, thus the CFC is not in the directory
    structure
    under which the Application.cfm file has dominion. So it will
    not apply
    in such a case.
    If this is so, the fix is to either move the CFC so that it
    is under the
    Application.cfm dominion. Or to provide it it's own
    <cfapplication...>
    tag with the desired application name to be able to access
    the desired
    application scope. This can be done directly in the CFC file
    or an
    Application.cfm file in the CFC folder hierarchy.
    Of course doing so really complicates the usefulness of
    having CFCs in a
    common place where they can be used by multiple applications
    equally.
    Thus providing a strong argument to the OOP concept of
    encapsulation.
    That an object (component) should not be aware of anything
    outside of
    itself and everything it needs to do its job should be passed
    into it.
    I.E. Pass the required application data into the component as
    arguments
    and make use of it that way.

  • Sharing application scope

    This question has been asked in the past but not answered completely, so here is my issue:
    I am currently working on a site that has two separate sections(one public section and another admin section), but need to share the same Application variables.
    Basic file structure....
    Root
    -- Admin  -- Application.cfc  -- index.cfm 
    -- Application.cfc  -- index.cfm  
    The public side will contain the application start and end code and the the admin Application.cfc will include the public application.cfc(<cfinclude template="../Application.cfc" />) and the login logic.   The reason I am trying to do this is that my application scope needs to be accessible by both sides. My understanding is that the CF server will treat this all as one application since they have the same name.
    During my testing, I set application.cfcroot variable in the public application.cfc.  That variable is not accessible in the admin subfolder.  My understanding is the fact that by including the original(public) application.cfc, the application.cfcroot variable will be accessible in subfolders(in this case: admin).  Th error I get is that the variable is undefined.  I test this by trying to dump the application right after I include it in my application.cfc located in the admin folder.  For example:
    Contents of application.cfc in root:
    <cfset this.name="myapp" >
    <cffunction name = "onApplicationStart">
         <cfset application.cfcroot = "myapp.cfcs.">
    </cffunction>
    Contents of application.cfc in admin folder:
    <cfinclude template="../Application.cfc" />
    <cfdump var="#application#" label="1" />
    error:
    Variable APPLICATION is undefined.
    Any ideas?

    Session management is enabled as the rest of my app relies on sessions.  Also, application variables are enabled in the administrator.  I had no idea it was in there, but it is checked.  Here are my Application.cfc files:
    Application.cfc (root/gemstartech directory)
    <cfcomponent>
              <cfset this.name="gemstartech" >
              <cfset this.sessionmanagement=true >
              <cfset this.setclientcookies=true >
              <cfset this.setdomaincookies=false >
              <!---This sets timeout to be 20 minutes(days, hours, minutes, seconds)--->
              <cfset this.sessiontimeout="#CreateTimeSpan(0,0,20,0)#" >
              <cffunction name = "onApplicationStart">
            <cfset application.cfcroot = "gemstartech.cfcs.">
              </cffunction>
              <cffunction name = "onRequestStart">
                        <cfparam name="CGI.REMOTE_ADDR" default="">
                        <cfinclude template="shared/udf.cfm">
              </cffunction>
    </cfcomponent>
    Application.cfc (root/gemstartech/admin directory)
    <cfcomponent extends="gemstartech.Application">
    <cfset this.applicationTimeout = "#createTimespan(1,0,0,0)#">
    <cfset this.sessionManagement = "true">
    <cfset this.sessionTimeout = "#createTimeSpan(0,0,20,0)#">
    <cffunction name = "onApplicationStart">
         <!--- The keyword super stands for the parent Application component. Calling its onApplicationStart method will initialize the variable application.cfcroot --->
         <cfset super.onApplicationStart()>
         <cfset application.testAdminVar= "aValue">
    </cffunction>
    <cfdump var="#application#" label="1" />
    <!--- log user out if they click 'logout' --->
    <cfif isDefined("url.logout") >
              <cfset structClear(session)>
              <cflogout>
              <cflocation url="index.cfm" addtoken="no">
    </cfif>
    </cfcomponent>

  • Everytime I turn on my computer running on Windows XP, a message appears from AppleSynchNotifier.exe-Unable to locate component - "this application has failed to start because CoreFoundation .dll was not found," Reinstalling did not fix problem.

    Everytime I turn on my computer running on Windows XP, a message appears from AppleSynchNotifier.exe - Unable to Locate Component -
    "This application has failed to start because CoreFoundation.dll was not found.  Re-installing the application may fix this problem.
    I uninstalled and re-installed itunes and the message still appears.
    How do I fix this??
    Thank you

    With that one, first try uninstalling and reinstalling your MobileMe Control Panel for Windows, robin. Does that make the error go away?

  • How to configure oracle 6i report server run time component with application server

    we got oracle 6i report server for developing the web based reports for our undergoing product. we r succesed in developing the web based reports using oracle 6i report server.But we r facing problems while deploying the product with oracle reports at clients place,why because the client does not have the oracle 6i report server. To solve this problem we have to configure the oracle 6i report server run time component with application server at client side , but we are unable to configure this component(that is CGI handler).

    You can run multiple instances of Reports Server in 6i.
    In tnsnames.ora, for each server, have a different name and each listening to different port.
    For example,
    server1.world = (ADDRESS = (PROTOCOL = TCP)(Host = myhost.mydomain.com)(Port = 1949))
    server2.world = (ADDRESS = (PROTOCOL = TCP)(Host = myhost.mydomain.com)(Port = 1950))
    Also, if you want to know about Reports Server Clustering, you may refer to "Publishing Reports" document on OTN:
    http://otn.oracle.com/docs/products/reports/pdf/A73173_01.pdf

  • Calling a method for application scope

    I have a method that initializes a hashtable.
    That method should be called once when my web app starts, I need to load that hashtable into memory so whenever a user needs a value from that hashtable, it readily access the hashtable and doesn't load it everytime it is called. How do I do that?

    Just put it in the application scope in the faces-config.xml?

Maybe you are looking for

  • I have purchased music that shows up on my iphone,but is not in the library on my pc?

    i have music ,purchased,available on my phone,but does not show up in the library on my pc.?

  • HTMLDB_item.Date with row selector

    Hi : In my application i am using htmldb_item.datepicker and row selector to insert the date object wise the problem wht i am facing is if suppose 10 rows are generated when i select 3rd row date and insert date picker date get populated in 2nd row s

  • RefreshUWLBackend : not working in a dummy - hidden iView on UWL page

    Experts, We are stuck with the recurring outstanding issue of "Uwl passive refresh post approval or rejection of task item" , the requirement is to auto refresh the UWL iView post approval of a task item. 1. User selects a task item from UWL, a BSP a

  • For loop don't updates

    Hi, First I'm new at labview , I'm trying to read 8 checkboxs vals and for each checkbox I'm queuing a single val witch will be a test. I have a problem with my for loop it simply won't update and staying at 0 val ( only one iteration )  vi is attach

  • Saving data for iphone & ipod

    I'm upgrading windows xp to windows 7 so i'm doing a clean install. I want to backup all of my data in itunes for my phone and ipod. i'm not worried about my music and playlists, but i do want to save my apps, data and settings for my phone and games