I am trying to load a class dynamically through reflection by using the method Class.forname("classname") as given in below code.
Class<? extends Layout> layoutClassName;
try {
    layoutClassName = (Class<? extends Layout>)   Class.forName(site.getSiteLayout());
} catch (ClassNotFoundException e) {
    layoutClassName= DefaultLayout.class;
}
I am trying to load a class dynamically if it is defined in configuration, otherwise provide the default implementation.
This works fine, but after a statistical analysis we found that approximately 80% of the times default implementation is used.
This means approx. 80% of times an Exception object is created . Since creating exception objects is heavy, I would like to avoid it and use some other logic to Identify if a class is present or not.
Please suggest.
PS: I am not looking for any significant performance boost, I am just trying to clean up my existing code.
 
Aucun commentaire:
Enregistrer un commentaire