Java thousand asked _08jdk detailed (016) _ATTACHAPI is what

Source: Internet
Author: User

Click to enter _ more _java thousand ask

1. What is ATTACHAPI?

The Attach API is a set of extension APIs provided by Sun, which is not a standard Java API. As the name implies, Attach, some programs are attached to the JVM. Simply put, a program is connected to a running JVM, and after the connection, the program can run in the JVM. This procedure is called the JVMTI Agent program.

We use it to dynamically set the Load proxy class (JVMTI agent) during the run, allowing us to easily monitor a JVM and run an additional agent.

Learn JVMTI agent look here: JVMTI is what

2. ATTACHAPI provides those interfaces

The Attach API is very simple in function and provides several functions as follows:

    1. Gets the description of all current JVM instances.
    2. Loads the agent program for the specified JVM.

Gets the description of all current JVM instances

Example:

publicclass TestAgent {    publicstaticvoidmain(String[] args) throws AttachNotSupportedException, IOException, AgentLoadException, AgentInitializationException {        List<VirtualMachineDescriptor> list = VirtualMachine.list();        for (VirtualMachineDescriptor vmd : list) {            System.out.println("pid:"":" + vmd.displayName());        }    }}

The results of the implementation are as follows:

Pid:8536:com.test.jvmti.testagent
pid:6697:

Loading the agent for the specified JVM

In the "How to write JVMTI agent" This article has a complete example, clearly explained by the ATTACHAPI for the specified JVM loading agent program, specifically as follows:

See JVMTI Agent Program here: How to write JVMTI Agent program

Java thousand asked _08jdk detailed (016) _ATTACHAPI is what

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.