• Post Reply Bookmark Topic Watch Topic
  • New Topic

container level scope variables  RSS feed

 
Joel Thompson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to create a singleton at the container level (to be shared by all my web apps). I am using OC4J, but I am hoping that the solution is not container specific... Any ideas?

Thanks!
[ October 10, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If all the web apps are running in the same JVM you can use a true singletone class, but there is no standards-compliant concept of a container-level scope.

There's always a shared database or file system as well.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this can be done in Tomcat by placing the class file that contains the singleton variable in one of the directories that is common to all applications (tomcat/shared/classes or tomcat/shared/lib). Not sure about OC4J.

Have you looked into JNDI?
 
Joel Thompson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it working in Tomcat by placing the library into the shared directory, and removing it from my webapps/WEB-INF/classes and/or lib directory; and deploying individual war files to the webapps dir.
(Thanks Ben and Bear...)

Now, I am trying to get OC4J working.

I created an ear with the following structure (x8.ear)
./adf-faces-impl.jar
./jsf-impl.jar
./META-INF/application.xml
./META-INF/data-sources.xml
./META-INF/jazn-data.xml
./META-INF/MANIFEST.MF
./META-INF/orion-application.xml
./webappX8.war
./webappX8B.war
./X8_jar.jar

The X8_jar.jar file has my singleton class in it, that both webappX8 and
webappXB will be using. At this point I am getting unresolved classes..:

cannot find symbol symbol : class UserSingleton location: class _scriplet1appB UserSingleton us=UserSingleton.getInstance();

When invoking either page (/X8/scriplet1app.jsp & /X8B/scriplet1appB.jsp)

Any thoughts on this? Thanks for your help!

[ October 11, 2006: Message edited by: Joel Thompson ]
[ October 11, 2006: Message edited by: Joel Thompson ]
 
Joel Thompson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently OC4J has a shared applib directory where you're supposed to put your shared jar files:
C:\JDev1013\j2ee\home\applib
Once I put it there, things worked.
The JDeveloper deployment tool doesn't seem to want to take care of this ...at least as far as I can tell.

However, I thought by it being in the top-level of the EAR file that it would get picked up... guess not.

Cheers!

-Joel
 
Joel Thompson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One other aspect of this problem that might be worth discussing (at least for me)...

I originally thought that thru some Context w/ my JSP, I could get access to the top-level container, as you can with page,session,application..etc. Yet this doesn't seem possible. Apparently there is no way to the top-level thread of your webserver, other than this way of configuration/deployment which is container specific.

Right?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct. There is no concept of a container level scope in the JSP (or Servlet) specifications.

Apparently there is no way to the top-level thread of your webserver


Not sure what you mean by that. There really isn't any such thing as a top-lvel thread.

All the tricks that are employed with regards to placement of the jar files is to make sure that your singleton is loaded by Tomcat's shared class loader so that it is accessible across web apps.

But there really isn't any sort of shared thread running.
 
Joel Thompson
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding is:
When you webserver starts up - that's the parent thread
and each http request is serviced by it's own thread,
children of the parent.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well of course the server is running in its own set of threads, but there's really no concept of those being any kind of parent or context level thread that you can access or employ for any reason.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!