Vincent Massol wrote:
> Hi,
>
> I need your expert advice here. The Log4JLogger class is declared as a final
> class. In my code, I use :
>
> Logger logger = new Log4JLogger(
> Category.getInstance(targetName));
>
> This is used in a generic method that is called to automatically log entries
> and exits of methods, so it is executed every time there is a log to be made
> for an entry/exit. It is thus called very often.
>
> I'd like to know if it has any performance issue. More specifically, I'd
> like to know if the final keyword helps for performance (as it does for
> final methods which are inlined) : I guess that even with the final keyword,
> there is always a new object instanciated in memory ...
The final declaration does help alot.
> So, I also guess that simply writing :
>
> Category category = Category.getInstance(targetName);
>
> would be more performant ?
By a couple nano/pico seconds
> Another solution would be to have a hashmap of all loggers and check in the
> hashmap whether the logger for a given targetName already exist and then use
> that logger if it does. However, the additional work (putting the instances
> in the hash, possibly with synchronisation (argh!), then doing an "if" and
> then fetching the logger from the hash) might overall be more costly that
> instanciating a new object.
Today's JREs are optimized to deal with small final classes. The garbage
collection overhead for these objeccts is actually _less_ than the overhead
of caching them.
--
"They that give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety."
- Benjamin Franklin
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>