Discussions

We know that a code in static block initializer is executed only one when a class is loaded. However, we disagree when a class is loaded: 1) when Jboss start (we use Jboss) or 2) when the class is first referenced in the application. or 3) None of the above.

2 is closer to correct, but I am not sure if it varies by application server. I believe that a class can be initialized onreference as you indicate, but since it is a static initialization block, it could be initialized when it is first loaded by the class loader which would most likely be the first time it is imported.

frankly, mu don't have a clue, nut did you try to place output a log entry from your class" static constructor? this may give you a hint. if you see your log entry during jboss' start-up, this may hint that the class is preloaded. if you see your log entry when you first call your beans, it would it's loaded only then.

TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations technology projects - with its network of technology-specific websites, events and online magazines.