Forums Register Login

Instantiates Logger as STATIC

+Pie Number of slices to send: Send

Hi Guyz,

Can anyone please let me know, is it advisable to declare the logger variable as static?
In all my previous concerns, I have done the same thing. Here while I analyzing the memory files, this variable took more memory and some of the developers advised me not to use Static keyword here.

private static final Logger logger = Logger.getLogger(myClass.class);




+Pie Number of slices to send: Send
What are they suggesting, a Logger instance per object instance? Would that not be far, far worse?
+Pie Number of slices to send: Send
Hi Paul,

Actually i got some bugs which related to the application performance.

We are using IBM WAS 7.0 as application server, EJB 3.0 for Business logic and SWT as the front end.
While performing some actions in the application, we have monitored that java.exe of the application server goes high and its not getting reduced while that action has been done. And one certain time, this results Heapdump file generation on the server profile.
We have analyzed the heap dump files and it says the "OutOfMemory" Exception and much memory took for this STATIC Logger instantiation.

Some of the developers gave suggestion that to remove the STATIC declaration for the logger.
for eg. public Logger logger = Logger.getLogger(myClass.class);

+Pie Number of slices to send: Send
Moreover, we have implemented this Log for some of the business logic classes to enable the logging functinality.
+Pie Number of slices to send: Send
@Bala: is your class (where ou have added the logger) is singlton ?
if YES, we CAN add Logger as instance variable
if NO then keep it static else there would be performance degradation ....

Also check the memoery foot print keeping loggers as static / instance.
Since LIFE (SCOPE ) of the STATIC variable would be different than the INSTANCE varaible; you MAY see some difference !

May I ask you few questions?
Have you ACTUALLY seen any performance improvement after defining loggers as INSTANCE fields?
Which Log api are you using? (hopefully Apache )
what is the appender size you have configured
is Appender on local drive or on network?

+Pie Number of slices to send: Send
"We have analyzed the heap dump files and it says the "OutOfMemory" Exception and much memory took for this STATIC Logger instantiation."

how did you find that the static logger was taking most of the memory?

This seems highly unlikely unless you start your application will really low parameters for the PermGen space. Class objects and class variables (i.e. static members) are stored in the PermGen area of the heap. This area is not subject to garbage collection. So if it is truly the static logger that is causing an OutOfMemoryError, then the only explanation is that you are allocating very little memory for the PermGen during your server startup.

See if this link helps
http://www.brokenbuild.com/blog/2006/08/04/java-jvm-gc-permgen-and-memory-options/

I don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2217 times.
Similar Threads
Naming logger instances
when we should go for a singleton class in java?
final instance variable
Understanding thread interference
EJB Passivation Question
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:41:49.