JAVA的JMX

package com.opensource.jmx;

/**
 *
 * @author Cache John
 * @email
[email protected]
 *
 */
public interface ServerMXBean
{
    public void doContinue(String temp);
   
    public String getServerValue(String port);
}

 

package com.opensource.jmx;

/**
 *
 * @author Cache John
 * @email
[email protected]
 *
 */
public class ServerMXBeanImpl implements ServerMXBean
{
   
    @Override
    public String getServerValue(String port)
    {
        return "port:" + port;
    }
   
    @Override
    public void doContinue(String temp)
    {
        System.out.println("continue");
    }
   
}

 

 

/**
 *
 * @author Cache John
 * @email
[email protected]
 *
 */
public class Main
{
   
    public static void main(String[] args)
    {
        ServerMXBean main = new ServerMXBeanImpl();
       
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        try
        {
            server.registerMBean(main, new ObjectName("myapp:type=webserver,name=ServerMXBean"));
           
            while (true)
            {
                main.doContinue("continue");
               
                Thread.sleep(3000);
            }
           
        }
        catch (InstanceAlreadyExistsException e)
        {
            e.printStackTrace();
        }
        catch (MBeanRegistrationException e)
        {
            e.printStackTrace();
        }
        catch (NotCompliantMBeanException e)
        {
            e.printStackTrace();
        }
        catch (MalformedObjectNameException e)
        {
            e.printStackTrace();
        }
        catch (NullPointerException e)
        {
            e.printStackTrace();
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }
       
    }
   
}

 

 

你可能感兴趣的:(java,bean,jmx,mxbean)