File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes JMX notification in tomcat server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JMX notification in tomcat server" Watch "JMX notification in tomcat server" New topic
Author

JMX notification in tomcat server

Shukla Atul
Greenhorn

Joined: Aug 17, 2008
Posts: 4
I have a requirement to get the notofication, when "HeapMemoryUsage" increase more than size "X" or decrease than size "Y".

In below program I have used mbean [java.lang:type=Memory] and added the notification listener on that

mbsc.addNotificationListener(mbeanName, listener, null, null);

I was under impression that, handleNotification(Notification notification, Object handback) will be invoked and the message will ne printed.

Please help me in this regard. or provide a sample program for tomcat server

Below code I am using :







Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19680
    
  10

Yes, well... at line 51 you add a listener which will wait for notifications from that MBean, and then the listener's handleNotification method will be called when any such notifications arrive.

But then just microseconds later, you disconnect from the JMX server and the program terminates. The chance that a notification would just happen to arrive in that time interval is extremely small. So don't close the server, and don't end the program. Let it run for a while and (if things are configured correctly) you should start seeing notifications.
Shukla Atul
Greenhorn

Joined: Aug 17, 2008
Posts: 4
Thanks Paul, So How to add the event/filter to get the notification (As In this case, I want a notification when HeapMemory used increase that size "X" or decrease than size "Y").
Shukla Atul
Greenhorn

Joined: Aug 17, 2008
Posts: 4
Can some suggest me what need to be use here ?
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19680
    
  10

Well, first of all I would suggest fixing your code so that it waits for all notifications from that JMX bean and displays them when they arrive. Right now, as I already said, your code only listens for notifications for a very short instant of time.

Once you have that working, you'll find you get more notifications than you want. That would be the time to start working with filters.
Shukla Atul
Greenhorn

Joined: Aug 17, 2008
Posts: 4
I have modified the code like this :



after adding the listener, I am putting the thread into sleep mode.

But still I am noit getting any alert?
 
Don't get me started about those stupid light bulbs.
 
subject: JMX notification in tomcat server
 
It's not a secret anymore!