Summary
Add new Service Provider Interface (SPI) to allow customization of InetAddress
API methods implementing host name and address resolution requests.
Problem
InetAddress
API methods delegate to built-in resolver to perform an Internet-Address (IP) resolution operations. The built-in resolver is responsible for forwarding the resolution requests to Operating System (O/S) resolver. Currently, there is no mechanism available to replace it with a custom resolver implementation.
The built-in resolver is problematic for Virtual Threads (project Loom) as it will block in the kernel, which limits the number of concurrent requests that can be sent in parallel. Providing an SPI would allow applications that need massive parallelism to replace the built-in implementation with a more scalable implementation.
Solution
Introduce a new Java standard service provider interface that allows installing a custom resolver implementation as the built-in resolver replacement. More information is available in JEP-418
Specification
The list of InetAddress
API methods that will use a custom resolver, if one installed:
- IP address (forward) lookup methods:
InetAddress.getAllByName
andInetAddress.getByName
- Host name (reverse) lookup methods:
InetAddress.getCanonicalHostName
andInetAddress.getHostName
Summary of new SPI classes added to 'java.net.spi' package:
InetAddressResolverProvider
- a new abstract class defining a service provider, and is, essentially, a factory forInetAddressResolver
resolvers.InetAddressResolverProvider.Configuration
- a new sealed interface describing the platform's built-in configuration for resolution operations.InetAddressResolver
- an interface that defines methods for the forward and reverse lookup operations.InetAddressResolver.LookupPolicy
- a final class whose instances describe the characteristics of a forward lookup operation.
List of API documentation changes that can be found in attached specdiff.zip
archive:
- Document new SPI classes added to
java.net.spi
package. - Changes to
java.net.InetAddress
: Extend class-level documentation to describe how new SPI works; update javadocs for existing API methods to useresolver
term. - Add new
inetAddressResolverProvider
permission to a table with the standard target names inRuntimePermission
class-level javadoc
Attached webrev.zip
also contains a change to src/java.base/share/classes/java/net/doc-files/net-properties.html
file as well as to the src/java.base/share/classes/module-info.java
file alongside to other implementation changes.
(changes to these two files are unfortunately not tracked by the specdiff)
- csr of
-
JDK-8244202 Implementation of JEP 418: Internet-Address Resolution SPI
-
- Resolved
-