OpenJDK Community to Develop New Service Provider Interface for Address Resolution
To enhance Java applications’ control over internet addressing, the OpenJDK community is proposing the development of a Service Provider Interface (SPI) for host name and address resolution. This initiative aims to provide a more flexible and customizable approach to how Java applications resolve host names and IP addresses, beyond relying solely on the operating system’s built-in resolver.
The proposal under consideration involves creating an SPI for the java.net.InetAddress
API. Currently, this API uses the operating system’s native resolver, which typically relies on a local hosts file and the Domain Name System (DNS) for resolving host names. By developing an SPI, the OpenJDK community seeks to allow Java applications and frameworks to use alternative resolvers, offering greater control and customization over resolution results.
One of the primary motivations for this proposal is to support customization. With a resolver SPI, developers would be able to implement custom resolution strategies or retrofit existing libraries with a custom resolver. This flexibility is particularly valuable for frameworks and applications that require specific resolution behavior or need to integrate with proprietary systems.
Additionally, the proposal addresses compatibility with Project Loom, which explores advanced Java VM features, including user-mode virtual threads. The current blocking nature of resolution operations in InetAddress
poses challenges for Loom’s virtual threads, as platform threads cannot service other virtual threads while waiting for a resolution to complete. An alternative resolver could be designed to implement the DNS client protocol in a non-blocking manner, thus enhancing compatibility with Loom’s threading model.
The SPI would also facilitate the adoption of emerging network protocols, such as DNS over Quick UDP Internet Connections (QUIC), Transport Layer Security (TLS), or HTTPS. By allowing seamless integration of these new protocols, the resolver SPI would future-proof Java applications and ensure they remain compatible with evolving internet standards.
Finally, the ability to control host name and address resolution is essential for prototyping and testing. Developers often need to manipulate resolution results for testing purposes, and a resolver SPI would provide the necessary control to achieve this. Oracle indicated that the proposal aligns with efforts to advance asynchronous programming in Java, addressing the limitations of legacy synchronous DNS lookups. By making the resolution process pluggable, the plan aims to modernize and enhance Java’s capabilities in handling network communications.