Can you explain in more detail (maybe with an example) what you mean exactly?
As far as I know, when you load a class in Java, it will never be unloaded (unless the class loader that loaded it is garbage collected itself). You don't need to manage loading classes yourself, the class loader does that for you. But I suspect that by "loading a class" you might mean something else than the Java class loading process?
one EJB which is calling different TaskHandler(interface implemented by different TaskHandler classes) for different Task. In Our application what we are doing we defined one HaspMap and in that we are storing these different TaskHandler so when new requests come to our EJB instead of loading TaskHandler we are checking availability of that taskHandler in HashMap if it is present then we are using that if not then we are loading it and storing it in same hashmap.
SO my question was what is best loading each time taskHandler means defining new object of task Handler or storing it in hashmap?. My EJB type is stateless and lets say 15 different taskHandler.
Aha, so as I suspected, your question is not about class loading at all. So, to phrase it differently, your question is the following.
Your application has a TaskHandler interface and several classes that implement that interface, and now there's a HashMap that contains instances of those classes, and for each request the relevant TaskHandler is looked up in the HashMap and called. You're asking why that HashMap is being used, instead of just creating a new instance of the relevant TaskHandler for each request.
Probably the HashMap is meant as a cache, to avoid creating a lot of objects (instances of the classes that implement interface TaskHandler). If those classes are also stateless, it's not necessary to create multiple instances of those classes. Not creating a new object for each request would also make the application more scalable.
Joined: Dec 07, 2005
Thanks A Bunch........
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Loadin class VS Storing it in HashMap and taking it back for further use