I have a java web application, which runs on a number of servers. Some of the servlets in this application load on startup to preload some data. The protocal for loading this data will change based on what server the application is deployed on. (The path of the files to be loaded change, also there are difference in security so getting some files is more involved then others). Is there a way that I can uniquely identify the server/machine that my application is on in the init function of a java servlet? I orginally was working with HttpServletRequest.getServerName(), which was enough, but it is not available in the init. I know about lazy initialization, so don’t tell me to do that, I am trying to avoid that if possible since the load times on these file are significant. If I could find the machine name that would be perfect but i can’t figure out how to get this out of the api’s. All I need is a way to uniquely identify machines from the init.
Thanks for any help.
Rather than making my application dependent on a (hardcoded) set of IPs, I’d use a simple String property bound to JNDI to identify each server.
Hardcoding an IP/hostname is usually not a good idea. Changes of infrastructure may happen right after you deploy your application 🙂
JNDI, on the other hand, is a standard way to get appserver’s resources. Binding a resource (a string property) to JNDI can be done in WAS admin console and getting the property value from JNDI is easy. And IBM even published a tutorial about that.