Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMX notification in tomcat server

 
Shukla Atul
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some suggest me what need to be use here ?
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic