Application scope objects(opinions wanted)
Hi All
Looking for educated opinions on the pros/cons of application scope objects. I am thinking about creating a read-only application scope hashmap representation of some static data in my database. When queried at the database level it can cause relatively long delays (3-4 seconds) and sometimes must be stored in many sessions on the server. I am thinking just one read-only object stored at app scope will cut down on the waste of memory, as well as skyrocket the speed of retrieving this data.
Please give me your opinions!!! I can tell you a little more about the app if you need more info to make an educated statement...
Thanks
Greg B
You can use the Properties Object for static data that can be persisted on a filesystem. Also, I assume that you can hold quite a bit of data too. A file read should be faster than a database query. Also if you do the connect once and save the connection for several reads, that works too. The only real slow operation, outside of large resultsets, would be the initial connect.
I always design up two or three possible solutions and sometimes I protpotype each one. Sometimes one of the tests will prove to be the exact opposite choice of the one you thought would work.
Now that I have written your response, I think that you could create a custom class to hold data, but would that not just be a copy of the properties object. If it's key/value you need, that's the choice.
Stand back and ask, "What is the data type of the high level objects?"
Also, SUN has good articles on almost everything in the JDK.
David Whitehurst
[email protected]
Similar Messages
-
Is Weblogic Cluster supports Application scope Objects?
Our Application is mainly depends on Application scope objects. On one m/c, it
is perfect.
Now, we want to support the failover , load balancing ... (High Availability).
I know, weblogic cluster supports HttpSessions, EjbObjects ... etc. What about
Application scope objects.
we are planning for weblogic server which supports the our requirements.
If not, what is the solution to make it work by using Weblogic server.
for eg: I can give what type of application we are developing --- similar to
textchat.
our application is real time application.
Even a singleton is not good enough as singletons are good only in the VM they were
created it. One way is to have a distributed object such as a stateful session bean of
which only one instance exists. U can create it at startup and store its handle in
some persistent storage as well as a singleton. This ensures that even if the
singleton doesnt contain it the refgerence to it can be obtained.
There will be some problems with this setup as people should not allow it to create
instances of it . Any such endeavor will lead to a CacheFullException.
But essentially that seems possible.
Even the 2.3 Servlet specification mandates that ServletContext and Application level
object is only valid inside the JVM which created it. HttpSessions are replicated
SessionContexts are not and are not likely to be in any J2EE application server
Sameer
Devi wrote:
> One more comment from my side,
> U mentioned "EXCEPT FOR JNDI" , if this is possible, how can we acheive?
> Can U give brief description ? Take textchat example itself? since, our application
> is almost have same mechanism. If it is < 1 sec delay means acceptable for this
> release.
>
> Thanks,
> Devi
>
> "Cameron Purdy" <[email protected]> wrote:
> >Weblogic doesn't support replicated / synchronized app scope objects
> >across
> >a cluster except for JNDI, which is probably not a good solution for
> >what
> >you are describing.
> >
> >If you need a real-time shared fault-tolerant fail-overable high-performance
> >load-balanced high-scale data store, then let me know when you find one
> >;-)
> >.... seriously, there are not a whole lot of good general purpose solutions
> >in this space. There are some things to look at but they are all expensive:
> >
> >Persistent PowerTier on top of Oracle - a caching entity EJB server
> >Jasmine (or whatever it is called this week) - an object oriented
> >distributed data store
> >....
> >
> >Peace,
> >
> >--
> >Cameron Purdy
> >Tangosol Inc.
> ><< Tangosol Server: How Weblogic applications are customized >>
> ><< Download now from http://www.tangosol.com/download.jsp >>
> >
> >
> >"Devi" <[email protected]> wrote in message
> >news:[email protected]...
> >>
> >> Our Application is mainly depends on Application scope objects. On
> >one
> >m/c, it
> >> is perfect.
> >> Now, we want to support the failover , load balancing ... (High
> >Availability).
> >>
> >> I know, weblogic cluster supports HttpSessions, EjbObjects ... etc.
> > What
> >about
> >> Application scope objects.
> >> we are planning for weblogic server which supports the our requirements.
> >>
> >> If not, what is the solution to make it work by using Weblogic server.
> >> for eg: I can give what type of application we are developing ---
> >similar to
> >> textchat.
> >> our application is real time application.
> >>
> >
> >
-
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.
-
Singleton vs ServletContext for storing application scope objects
Hi all,
I would like to share some bean objects between all sessions inside the same web application, i.e. all users should access the same beans.
Which is the best way, to store the beans, use a singleton ore put them into the ServletContent vs get/setAttribute?
How about large objects, are there any limitations?
Thanks
Mert
Edited by: mahmut1 on Oct 22, 2009 3:32 AMI must confess I am a heretic. I would use a singleton. I try to use as few servlet services as possible when working with servlets; that way the code has a fighting chance of being reusable outside the servlet system.
As to "singletons are evil": well, if we are talking about ServletContext.setAttribute(), that is a singleton. It is a singleton hash table. The difference between the attribute hash table and a hash table singleton you write yourself is with attributes you don't automatically see the source code that defines the singleton, so you get to pretend you are not using a singleton.
protected Hashtable myAttributes;Haha! There, I just showed how the singleton hash table is implemented in a popular web server! -
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
-
Application scope problem in a JSP
Hi,
I try to store an object with the following code :
getServletContext().setAttribute("application", app);
Later I want to access this object from a JSP with :
<jsp:useBean id="application" scope="application" class="de.skillworks.SWApp"/>
that dosn't work !? I can not debug my application because the jsp is initializing my app object new. When I try in my JSP :
SWApp app = (SWApp)pageContext.getServletContext().getAttribute("application");
it works fine. I get my object which I have store in my servlet.
In a Tomcat environment my code is working just the Jdeveloper has a problem with it.
nullAndy -
The web-to-go server has difficulty dealing with sessions. Testing in Tomcat is a good alternative, and this is resolved in Oracle9i JDeveloper.
Hope this helps,
Lynn -
I'm curious about which is best from a performance standpoint -<br /><br />All of our flex calls access a single java pojo. In my remoting-config.xml I'm currently declaring the destination a property scope of 'application': <br /><br /><destination id="UIServicesDelegate"><br /> <channels><br /> <channel ref="my-amf"/><br /> <channel ref="my-local-amf"/ <br /> </channels> <br /> <properties><br /> <factory>spring</factory><br /> <source>uiServicesDelegateBean</source><br /> <scope>application</scope><br /> </properties><br /></destination><br /><br />All of the UIServiceDelegate methods are stateless however, so I'm wondering if I'm gaining anything by giving it scope session. Since their all stateless I"m assuming application scope would be the best from a performance standpoint? I'm assuming in this case only one object will ever be instantiated? <br /><br />Assuming it was between Session and Request scope, is there a lot of overhead instantiating the new server side object each time? I would assume performance would be better using the Session in this case, with the only draw back of some server-side ram being chewed up storing the object in the Session. <br /><br />If you want "singleton" type approach, I figure just using application scope is the preferred approach?
You wont get any api for directly accessing Servlet application objects from any ejb. I dont think MDB either solves your problem directly. Indirectly you can place a request to some servlet (should be there for each JVM and web application ) and update your application scope variable. I would suggest you to cache the data in database if the size of cache is large. otherwise any open caching tools may help you.
-
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-Heinzyou 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. -
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 -
ACCESSING APPLICATION SCOPE FROM FILTERS
HI
Is there any way to access the application scope from inside security filters? i have a class that implements the Filter interface and i'm trying to access the application scope in the doFilter method.
The FacesContext Object is null, and i'm only able to access the session scope using request.getSession()
I want to check for global application properties that are saved in the application scope.
Thanksthank you BalusC it's working
-
Will the Application Scope be shared across the cluster in a multi-node OC4
Hi,
I have the following requirement:
Users of the application can only have single (browser) session. When a user who already has a session connects again, he should no longer be allowed to access the older session.
My proposed implementation is:
- After successful login – possibly using a Session Listener - an entry is made in a HashMap UserSessions that lives in the application scope. Key is the username, value is the session id (HttpSession.getId()).
- For every request, using a ServletFilter, we check whether the session is still in the UserSessions HashMap for the current user. If a new session has been created for the same user, the session id for that new session is in the UserSessions map and the servletfilter will not find the session. In that case, the filter should invalidate the session and forward to the user to an error page.
However, the application will run on a multi-node OC4J cluster. I am starting to wonder:
Will the Application Scope be shared across the cluster in a multi-node OC4J environment?
I know session state can be shared. But what application state/scope?
Does anyone know? Do I have to do anything special in the cluster or the application to get this to work?
Thanks for your help.
Lucasgday Lucas --
Application scope is not replicated across JVM boundaries with OC4J.
I'm sure this used to be described in the doc, but I can't find it now from a quick scan.
If you wanted to use this type of pattern, you could look to use a Coherence cache as distribution mechanism to share objects across multiple JVMs/nodes.
-steve- -
Destroy in JavaBean with application scope?
Hi,
I am using a java bean in my jsp application with scope "application". I know that this java bean will be terminated only when the server stops or shuts down (Apache Tomcat 5.5).
I need to cleanup something manually when the server shuts down. Can anyone tell me what method will be called, or that I can override, to clean up?
I tried finalize and valueUnbound (implements HttpSessionBindingListener) with no luck... I just can't find a equivalent to destroy in Servlets (I can't use servlets, must use javabeans+jsp)...
Any sugestion?
thanks in advance for your timeThere is an indirect way if you know servlets. The "application" implicit object that you use in your JSP is the javax.servlet.ServletContext object. Instead of declaring your bean using the jsp:useBean tag, directly put your objects into the ServletContext using ServletContext.putAttribute() method. Objects put in the ServletCOntext are available to all pages in the application. Just use the ServletContext.getAttribute() method to retrieve this bean in any other page.
To "kill the bean", just reset the value of this object to null by calling putAttribute(null). -
Killing a bean with application scope?
Is there any way to kill a bean with application scope?
I am writing a web application, that most likely the browser window will never be closed. The problem is a user is authenticated onto our site but because the bean containing the users acct info is application scope, if another user logs in it still shows the old user as logged in. So on logout i would like to kill the application, the bean, servletContext...anything that will refresh the bean and the corresponding jsp. Any help is much appreciated.There is an indirect way if you know servlets. The "application" implicit object that you use in your JSP is the javax.servlet.ServletContext object. Instead of declaring your bean using the jsp:useBean tag, directly put your objects into the ServletContext using ServletContext.putAttribute() method. Objects put in the ServletCOntext are available to all pages in the application. Just use the ServletContext.getAttribute() method to retrieve this bean in any other page.
To "kill the bean", just reset the value of this object to null by calling putAttribute(null). -
OC4J- NamingException: Not in an application scope
I have a JMS program(ResourceAdapter) which I am deploying on OC4J 10g (10.0.3.0.0) .
The program first creates InitialContext object and and then looks for the JMS connection factory and JMS queue in the "start" method of resource adapter. When I deploy this program everything works fine first, but later when I bounce oc4j, I start
getting "javax.naming.NamingException: Not in an application scope"
exception. Can someone suggest me what could be causing this?
I have tried restarting the oc4j with userThreads option but it doesn't help.
Program code:
try{
mContext = new InitialContext();
System.out.println("**************1**********");
mQueueCF =
(QueueConnectionFactory)mContext.lookup("ojmsjra/MyQCF");
System.out.println("**************2************");
mQueue= (Queue)mContext.lookup("ojmsjra/QUEUE");
System.out.println("**************3*********");
}catch(Exception ex){
ex.printStackTrace();
After oc4j is restart only "**1**" gets printed and the following exception(lookup fails)
04/09/27 15:56:15 javax.naming.NamingException: Not in an application scope - start Orion with the -userThreads switch if using user-created threads
04/09/27 15:56:15 at com.evermind.server.PreemptiveApplicationContext.getContext(PreemptiveApplicationContext.java:29)
04/09/27 15:56:15 at
com.evermind.naming.FilterContext.lookup(FilterContext.java:127)
04/09/27 15:56:15 at
com.evermind.server.PreemptiveApplicationContext.lookup(PreemptiveApplicationContext.java:48)
04/09/27 15:56:15 at
javax.naming.InitialContext.lookup(InitialContext.java:347)
04/09/27 15:56:15 at
oracle.panama.messaging.driver.DriverResourceAdapter.<init>(DriverResourceAdapter.java:40)
04/09/27 15:56:15 at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
04/09/27 15:56:15 at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
04/09/27 15:56:15 at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
04/09/27 15:56:15 at
java.lang.reflect.Constructor.newInstance(Constructor.java:274)
04/09/27 15:56:15 at java.lang.Class.newInstance0(Class.java:306)
04/09/27 15:56:15 at java.lang.Class.newInstance(Class.java:259)
04/09/27 15:56:15 at
com.evermind.server.connector.deployment.ConnectorArchive.createJavaBeanInstance(ConnectorArchive.java:462)
04/09/27 15:56:15 at
com.evermind.server.connector.deployment.ConnectorArchive.start(ConnectorArchive.java:360)
04/09/27 15:56:15 at
com.evermind.server.Application.initConnectors(Application.java:444)
04/09/27 15:56:15 at
com.evermind.server.Application.postInit(Application.java:681)
04/09/27 15:56:15 at
com.evermind.server.Application.setConfig(Application.java:201)
04/09/27 15:56:15 at
com.evermind.server.Application.setConfig(Application.java:170)
04/09/27 15:56:15 at
com.evermind.server.ApplicationServer.initializeApplications(ApplicationServer.java:1708)
04/09/27 15:56:15 at
com.evermind.server.ApplicationServer.setConfig(ApplicationServer.java:1412)
04/09/27 15:56:15 at
com.evermind.server.ApplicationServerLauncher.run(ApplicationServerLauncher.java:93)
04/09/27 15:56:15 at java.lang.Thread.run(Thread.java:536)Gedomir,
Thanks for the reply. But unfortunately it did not work. I was using the default initial context. I tried setting the properties as well. Even then it did not work.
I am trying this with oc4j_extended.
Thanks again. -
Accessing Application Scope from an EJB
I'm not sure of the best way of doing this:
The set up:
We have a rather large J2EE application that is composed of only servlets and JSPs at the moment (When the application began development EJB was in its infancy and not feasible for the development of the app). Some of the new deployments of the app involve distributed webserver over 4 JVMs and 2 machines. When a user connects the servers load balancing decides which particular JVM they should be connected to. We perform large data caching into the servlet application scope to avoid having to access the database every time a change is made by a user to certain tables in our database. The data caches are stored in hashtables in the servlet application scope.We seem to have no way to determine what other JVMs are running or which JVM a user is currently connected to.
The problem:
Apparently the application scope is for a particular JVM. This means that when a user makes a change to a data cache the change doesn't effect users in the other 3 JVMs of the application, only the users who, due to load balancing, happened to be connected to the same JVM as the one where the change was made.
Our possible solution:
We were thinking that we could set up a queue (such as MQSeries from IBM) and any time a change is made to one of these data caches put a message on the stack saying that the particular table had been updated. Then a MDB would be listening asynchronously and digest the message from the Queue and recache the tables from the database.
So here are my questions:
1. Would this work? Would putting a MDB in the EJB Container give each JVM the MDB in the first place, or would this mean it would pick one of the JVMs to deploy the MDB on and still not fix our problem.
2. If this does work, how do I access the hashtables stored in the Servlet Application scope from the MDB. I can't seem to find any method available to the MDB (or any EJBs for that matter) that can access the servlets Application scope.
3. Is this the best way to do this? Or is there a better way to share data between seperate JVMs that I don't have a URL to (It's all ambiguous and handled by the server as to which JVM actually gets the connection.)
Just in case this is needed:
We are running IBM WebSphere 5 Application Server and the database could be anything from DB2 to Oracle.
Thanks in advance for any possible help.You wont get any api for directly accessing Servlet application objects from any ejb. I dont think MDB either solves your problem directly. Indirectly you can place a request to some servlet (should be there for each JVM and web application ) and update your application scope variable. I would suggest you to cache the data in database if the size of cache is large. otherwise any open caching tools may help you.
Maybe you are looking for
-
Page Headers in XML Publisher report
Hi, I've created a table to display the item details. If this table goes to the next page then i have to display the column names in 1st record in the table...followed by the item details.Consider that i have item details with 100 lines. In the 1st p
-
Trouble installing Adobe Photoshop Lightroom 5.3
This is my second download in a week to try to upgrade to Adobe Photoshop Lightroom 5.3. I get this error message. "Adobe Photoshop Lightroom 5.3 can't be installed on this disk. An error occured while evaluatiing JavaScript for the package." How do
-
II've had my ipad mini for just under a year it still has warranty for about 3 weeks. just recently i was on the internet and this logo just appeared burnt on the screen. When I went on the home it still stayed on. I don't know If I should go to the
-
HT4619 How to test the audio input port
How do you tell if the Audio in port is functioning. I have tried everything and cannot get the computer to accept audio from the external mic. or guitar.
-
Been debating this for awhile.. why not use 1 of the 2 30" ACD's for gaming. According to VP at XBOX division: Xbox 360 will support HD component video output, which is compatible with nearly every HD-ready TV on the market today. Were poised to hit