Java Reference
In-Depth Information
Listing 6.1
Polling.java
package jmxbook.ch6;
import javax.management.*;
Extend
support class
for sending
notifications
public class Polling extends NotificationBroadcasterSupport
implements PollingMBean, Runnable
{
private boolean stop = true;
private int index = 0;
public Polling()
{
}
public void start()
{
try
{
stop = false;
Thread t = new Thread( this );
t.start();
Create Thread
to run loop
}
catch( Exception e )
{
e.printStackTrace();
}
}
public void stop()
{
stop = true;
}
public void run()
{
while( !stop )
{
try
{
Thread.sleep( 1000 );
System.out.println( "Polling" );
}
catch( Exception e )
{
e.printStackTrace();
}
Notification notif = new Notification(
"ch6.PollingMBean.counter",
this, index++ );
sendNotification( notif );
B
Create and send
notification
Search WWH ::




Custom Search