« Memory Leaks made easy | Main | What's this? A JAR File with MANIFEST.MF Only? »

The dangers of the InitialContext default constructor

The JNDI context

In Java EE you have to use the JNDI context to lookup objects. This works quite well in many cases. To start with you have to obtain an InitialContext which uses some configuration information on how to connect to the real host. This information is provided either directly through a Properties collection or a jndi.properties file from the class path.

Default Constructor InitialContext within the Container

If you use the InitialContext within the Container you can usually use the InitialContext default constructor. This creates the context for the surrounding container.

Default Constructor InitialContext in a Client

If your using the default constructor for the InitialContext, you can provide a jndi.properties file in your class path to hint the constructor to the real host. This is quite easy to use and highly configurable.

Choke Point

As long as you stay in one environment everything works smooth and fine. But things get difficult if  you want to connect to a different Java EE container from within a container. How? Simply consider a helper method getting information from the JNDI context through InitialContext() and an explicit connection with InitialContext(props). While the your application/facade connects to the correct container, the helper method takes the information from the container it is located in... If both contexts are supposed to connect to the same container this doesn't work correctly anymore. Not convinced? Give it some thoughts...

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on September 26, 2007 12:15 AM.

The previous post in this blog was Memory Leaks made easy.

The next post in this blog is What's this? A JAR File with MANIFEST.MF Only?.

Many more can be found on the main index page or by looking through the archives.

Top Tags

Powered by
Movable Type and Oracle