X

Technical Articles relating to Oracle Development Tools and Frameworks

  • Misc
    April 5, 2012

Application Scope v's Static - Not Quite the same

Duncan Mills
Architect

An interesting question came up today which, innocent as it sounded, needed a second or two to consider. What's the difference between storing say a Map of reference information as a Static as opposed to storing the same map as an application scoped variable in JSF? 

From the perspective of the web application itself there seems to be no functional difference, in both cases, the information is confined to the current JVM and potentially visible to your app code (note that Application Scope is not magically propagated across a cluster, you would need a separate instance on each VM).

To my mind the primary consideration here is a matter of leakage. A static will be (potentially) visible to everything running within the same VM (OK this depends on which class-loader was used but let's keep this simple), and this includes your model code and indeed other web applications running in the same container. An Application Scoped object, in JSF terms, is much more ring-fenced and is only visible to the Web app itself, not other web apps running on the same server and not directly to the business model layer if that is running in the same VM.

So given that I'm a big fan of coding applications to say what I mean, then using Application Scope appeals because it explicitly states how I expect the data to be used and a provides a more explicit statement about visibility and indeed dependency as I'd generally explicitly inject it where it is needed. 

Alternative viewpoints / thoughts are, as ever, welcomed...

Join the discussion

Comments ( 2 )
  • Vik Thursday, April 5, 2012

    " A static will be (potentially) visible to everything running within the same VM"

    Willn't that be limited by the scope of the class where it is defined?


  • Duncan Sunday, April 8, 2012

    Yes - hence the "(potentially)" in the sentence.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.