• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

JMX notification in tomcat server

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :







 
Sheriff
Posts: 27463
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can some suggest me what need to be use here ?
 
Paul Clapham
Sheriff
Posts: 27463
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic