liveBook · Manning

Dynamic proxy

As explained in Troubleshooting Java, Second Edition

A dynamic proxy is a runtime-generated object that implements specified interfaces and delegates method calls to an invocation handler.

A dynamic proxy is a runtime-generated object that implements an interface and selects the method implementation during execution. Frameworks use it to keep an abstraction separate from its implementation. section 6.1

This decoupling makes framework capabilities convenient to call but difficult to investigate by reading application code. The visible interface may conceal the dependency method that performs the real work. section 6.1

When investigating code that uses dynamic proxies:

  • Start with the observable symptom, such as an endpoint that takes about five seconds to respond. section 6.1
  • Sample the running process, expand active-thread stacks, and inspect methods from both the application and its dependencies. section 6.1
  • Use execution time and waiting behavior to locate the hidden implementation responsible for the delay. section 6.1

Feign interface hiding an HTTP implementation

An OpenFeign interface declares a POST request to /delay/{n}. Application code calls the interface, while the framework supplies the actual HTTP implementation at runtime. A profiler can reveal the dependency methods involved in the request. section 6.1

Figure 6.7 The framework keeps the implementations for an abstraction separate and provides them dynamically during execution. Because the implementation is decoupled and the app provides it during run time, it’s more difficult to find it by reading the code.

Shows how a framework keeps implementations separate from an abstraction and provides them during execution. section 6.1

How Troubleshooting Java, Second Edition covers it

How deep it goes
Defines runtime method selection and demonstrates its diagnostic effect, but does not explain proxy internals or handler mechanics.
Examples
Uses an OpenFeign HTTP client, a delayed httpbin.org endpoint, profiler stacks, and dependency timing observations.
What you can do after
Diagnose hidden dependency behavior by sampling execution and inspecting stack traces and timing.
How it connects
Connects interfaces, frameworks, dependencies, HTTP clients, stack traces, and profiling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.