In the Oracle Application Server it is standard practice to set up a cluster with multiple application server instances hosting multiple OC4J instances each run atop of multiple JVMs.
Frequently when executing a specific application instance (servlet/EJB/Web service), it can be useful to have the exact location you are running - which Application Server instance, which specific OC4J instance and sometimes even the exact JVM instance. Sometimes you need this for your application to make some application centric decision, but more often it is useful for debugging when working in large clusters.
This blog is inspired by Steve Button's work where he built a very cool utility for session tracking in a cluster which implicitly revealed this information - he needed it himself while building it to debug as well to show to the user.
So how do you determine this on Oracle Application Server? There are several system properties that will help you out, specifically:
- oracle.home - the physical directory in which your application server is installed
- oracle.oc4j.instancename - the name of your OC4J instance
- oracle.ons.instancename - your OracleAS instance name
- oracle.ons.indexid - a combination of your OC4J instance name, the group it belongs to and the actual JVM executing it (for example if there is > 1 JVM you have configured as per my previous post on this topic)
To try out these properties, I deploy a servlet to that OC4J instance javaee_1 and within that servlet I have the following code:
Oracle home name: " + System.getProperty("oracle.home"));
OC4J Instance name: " + System.getProperty("oracle.oc4j.instancename"));
AS Instance name: " + System.getProperty("oracle.ons.instancename"));
Instance:Group:JVM PID: " + System.getProperty("oracle.ons.indexid"));
Oracle home name: D:\oracle\product\soa_javaee
OC4J Instance name: javaee_1
AS Instance name: soa_javaee.MLEHMANN-LAP
Instance:Group:JVM PID: java_ee1.javaee_group.2
Pretty useful information ... try it out :-)