Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4267882
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:57:35+00:00 2026-05-21T06:57:35+00:00

I should connect to a java program on localhost jvm using JMX. In other

  • 0

I should connect to a java program on localhost jvm using JMX. In other words I want to develop a JMX client to config a java program on localhost.

  • Don’t recommend using JConsole! JConsole is not suitable because it is general JMX client and have negative effect on main program performance.

  • Samples on oracle site use RMIConnector and host:port params but I don’t know:
    where should set jmx port?

  • JConsole have an option to connect to java processes by PID. But I don’t find any method in JMX api that have PID as input param.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:57:36+00:00Added an answer on May 21, 2026 at 6:57 am

    We use something like the following to programatically connect to our JMX servers. You should run your server with something like the following arguments:

    -Dcom.sun.management.jmxremote
    -Dcom.sun.management.jmxremote.authenticate=false
    -Dcom.sun.management.jmxremote.port=1234
    -Dcom.sun.management.jmxremote.ssl=false
    

    To bind to a particular address you’ll need to add the following VM arguments:

    -Djava.rmi.server.hostname=A.B.C.D
    

    Then you can connect to your server using JMX client code like the following:

    String host = "localhost";  // or some A.B.C.D
    int port = 1234;
    String url = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";
    JMXServiceURL serviceUrl = new JMXServiceURL(url);
    JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceUrl, null);
    try {
       MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection();
       // now query to get the beans or whatever
       Set<ObjectName> beanSet = mbeanConn.queryNames(null, null);
       ...
    } finally {
       jmxConnector.close();
    }
    

    We also have code that can programatically publish itself to a particular port outside of the VM arguments but that’s more fu than you need I think.


    In terms of connecting “by pid”, you need to be using Java6 to do it from Java land as far as I know. I’ve not used the following code but it seems to work.

    List<VirtualMachineDescriptor> vms = VirtualMachine.list();
    for (VirtualMachineDescriptor desc : vms) {
        VirtualMachine vm;
        try {
            vm = VirtualMachine.attach(desc);
        } catch (AttachNotSupportedException e) {
            continue;
        }
        Properties props = vm.getAgentProperties();
        String connectorAddress =
            props.getProperty("com.sun.management.jmxremote.localConnectorAddress");
        if (connectorAddress == null) {
            continue;
        }
        JMXServiceURL url = new JMXServiceURL(connectorAddress);
        JMXConnector connector = JMXConnectorFactory.connect(url);
        try {
            MBeanServerConnection mbeanConn = connector.getMBeanServerConnection();
            Set<ObjectName> beanSet = mbeanConn.queryNames(null, null);
            ...
        } finally {
            jmxConnector.close();
        }
    }
    

    I’ve also the author of SimpleJMX package which makes it easy to start a JMX server and publish beans to remote clients.

    // create a new server listening on port 8000
    JmxServer jmxServer = new JmxServer(8000);
    // start our server
    jmxServer.start();
    // register our lookupCache object defined below
    jmxServer.register(lookupCache);
    jmxServer.register(someOtherObject);
    // stop our server
    jmxServer.stop();
    

    It does have a client interface as well but right now it doesn’t have any mechanisms to find processes by PID — only host/port combinations are supported (in 6/2012).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to connect to a my facebook application using the facebook java api
Should developers avoid using continue in C# or its equivalent in other languages to
Basically I'm using Flash to connect to a Java server. Despite my Java application
I have a problem with my android application which should connect to java tcp
I am using Mongodb Java driver for my Java client application. it needs to
I am trying to connect to server using a Java socket. I am trying
I have been trying to make my C++ TAO (v1.6) client connect to java
What library should I use to connect to odbc from python on windows? Is
Should I still be using tables anyway? The table code I'd be replacing is:
Okay, so I'm working on a project where I use a Java program to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.