For a static class variable (the class is bundled in the EAR deployed to app server), what's its life cycle ? Is it instantiated when the server starts and stays alive as long as the server is on ? Of course, when server crashes or is turned off, this variable is gone.
A class or interface may be unloaded if and only if its class loader is unreachable.
So, Class loading and unloading is not related with server start up and shutdown. it is related with ClassLoader.
Each web application deployed in server will have it's own classloader. Class Loader will be unavaliable only when web application is undeployed. So, static Class variable stays till web application is in service.
Originally posted by FY Hsieh: Is it instantiated when the server starts and stays alive as long as the server is on ?
It is instantiated with the first reference to it , nothing to do with the applications startup.But if the static variable is referenced then it gets unloaded with the unloading of the application.
To add to what Prabhu said : Each web application has its own classloader (following the delegation model of classloading.), so when you bring down an application context , that classloader specific to that application also dies and everyting loaded using that classloaded is unloaded.