The dynamic agent of Java EE

Source: Internet
Author: User

JDK dynamic proxies are primarily using the Java Reflection mechanism (both java.lang.reflect packages)

Dynamic agents: When a program runs, it uses the JDK to provide a tool class (proxy), which dynamically creates a class that is typically used for proxies.

proxy class need to implement invocationhandler interface, and override the invoke method, the parameters in the Invoke method are generated from the bottom of the system and do not need to be given, Just use method methods to override the method.

Object proxyobj = proxy.newproxyinstance (parameter 1, parameter 2, parameter 3);

Parameter 1:ClassLoader, which is responsible for dynamically creating classes, loads into memory. The current class . Class.getclassloader ();

Parameter 2:class[] interfaces, the proxy class needs to implement all the interfaces (deterministic methods)that are represented by the class instance . GetClass (). Getinterfaces ();

Parameter 3:Invocationhandler, the request processing class, the proxy class does not have any function, when each method of the proxy class executes, invokes the processing class invoke method.

Voke (Object proxy , Method, object[] args)

Parameter 1: proxy instance

Parameter 2: currently executing method

Parameter 3: Method actual parameters.

The dynamic agent of Java EE

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.