I have performance problem while doing first API call to my J2EE applications. So I wanted to do Class.forName to preload the classes while doing application initialization. But I heard that it is prohibited by J2EE standard/BEA implementation (I might be completely wrong). Is it so? Are there any other limitation of doing forName in J2EE container.
views:
21answers:
1I have performance problem while doing first API call to my J2EE applications. So I wanted to do Class.forName to preload the classes while doing application initialization.
So basically, you just want to move the overhead :) I don't see the difference (user experience maybe) but ok, why not.
But I heard that it is prohibited by J2EE standard/BEA implementation (I might be completely wrong). Is it so? Are there any other limitation of doing forName in J2EE container.
The context is a bit unclear but, to my knowledge, it isn't. And that's actually something that the Pet Store app is/was doing. Quoting EJB Restrictions:
Why all the restrictions on creating class loaders and redirection of input, output, and error streams?
Class loading is allowed, but creating custom loaders is not, for security reasons. These restrictions exist because the EJB container has responsibility for class loading and I/O control. Allowing the EJB to perform these functions would interfere with proper operation of the Container, and are a security hazard.
The Java Pet Store has code that loads classes from inside an enterprise bean class using
Class.forName()
, in StateMachine.
But why don't you just try it?