• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to detect Java EE container environment

 
James Krell
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for a way to detect if a class is executing in a Java EE web application server environment, or simply running in a stand-alone JVM. The particular �flavor� of the server is not of interest. It could well be JBoss, WebLogic, WebSphere, etc. My service classes are ** mostly ** designed to be agnostic to environment, ** except ** for whether or not synchronization primitives are permitted. I have �wrapped� Thread.sleep() and Object.wait() in such a way that my routines can avoid using them if they can detect they are running in a Java EE web application server.

I have a strong negative (I believe) test for the presence of a web application server by using the current ClassLoader to attempt to load �javax.ejb.EJBException� � when the load fails, I can �reasonably� assume that I am not in a Java EE web application server.

However, this test is prone to �false positive� indications. My service classes support their own configuration options using XML declarations that look like this.


<type>JNDI</type>
<initialContext>weblogic.jndi.WLInitialContextFactory</initialContext>
<providerUrl>t3://remote.hostname.com:7001/</providerUrl>

The tricky bit is that my services can be running in a stand-alone JVM, using a WebLogic JAR file for the JNDI initial context factory and locate the desired resources in the remote WebLogic server instance. All functions in the running services are happy with the JNDI resources; but I have no reliable way to inform my classes that they are truly stand-alone, and not running in WebLogic itself.

The secondary issue is that WebLogic is one example. I work in an environment where multiple different Java EE vendor products and open source products are used. So I cannot rely on specifically WebLogic indications.

Thank you for your assistance
 
Sandeep Murthy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ideally, from design perspective, it should be well known before hand whether the application that is being developed will be deployed in an App Server environment; or if it will be used as a stand alone java application.
Could you throw some light as to why you intend to use your application in both App server environment and in stand alone mode.
 
James Krell
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am implementing a set of business specific service routines as "support services," not as a particular "application." The services are not restricted by most of the design criteria to any particular execution environment. The internal details of which are confidential and proprietary. Part of the high-level service requirement is the ability to provide "pool management" of a variety of different types of Objects (POJO's), one again independently of the details of the execution environment.

An implementation choice (among several) is to use Apache Commons Pooling and a variety of other "caching and management strategies." Some of these "strategies" involve "cache evictors" which can (possibly) run in independent execution threads. Clearly this is a violation of the EJB 2.0 Specification and later. It is my desire to "wrap" synchronization primitives in a "service layer agnostic" manner that led to my earlier post.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!