Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instantiates Logger as STATIC

 
Balakrishnan Nagarajan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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);




 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are they suggesting, a Logger instance per object instance? Would that not be far, far worse?
 
Balakrishnan Nagarajan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);

 
Balakrishnan Nagarajan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moreover, we have implemented this Log for some of the business logic classes to enable the logging functinality.
 
K Abhijit
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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?

 
Bhay Zone
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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/

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic