public static final class DnsOptions.Builder
extends Object



Builder for DnsOptions.

Summary

Public constructors

Builder()

Public methods

DnsOptions build()

Creates and returns the final DnsOptions instance, based on the values in this builder.

DnsOptions.Builder setPersistHostCache(int state)

Sets whether the DNS cache should be persisted to disk.

DnsOptions.Builder setPersistHostCachePeriod(Duration persistHostCachePeriod)

Sets the minimum period between subsequent writes to disk for DNS cache persistence.

DnsOptions.Builder setPreestablishConnectionsToStaleDnsResults(int state)

Sets whether Cronet should use stale cached DNS records to pre-establish connections.

DnsOptions.Builder setStaleDns(int state)

Sets whether to use stale DNS results at all.

DnsOptions.Builder setStaleDnsOptions(DnsOptions.StaleDnsOptions staleDnsOptions)

Sets detailed configuration for stale DNS.

DnsOptions.Builder setUseHttpStackDnsResolver(int state)

Enables the use of the HTTP-stack-specific DNS resolver.

Inherited methods

From class java.lang.Object

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Public constructors

Builder

public Builder ()

Public methods

build

public DnsOptions build ()

Creates and returns the final DnsOptions instance, based on the values in this builder.

Returns
DnsOptions This value cannot be null.

setPreestablishConnectionsToStaleDnsResults

public DnsOptions.Builder setPreestablishConnectionsToStaleDnsResults (int state)

Sets whether Cronet should use stale cached DNS records to pre-establish connections.

If enabled, Cronet will optimistically pre-establish connections to servers that matched the hostname at some point in the past and were cached but the cache entry expired. Such connections won't be used further until a new DNS lookup confirms the cached record was up to date.

To use cached DNS records straight away, use setStaleDns(int) and StaleDnsOptions configuration options.

This option may not be available for all networking protocols.

Parameters
state int: one of the DNS_OPTION_* values.
Value is one of the following:
Returns
DnsOptions.Builder the builder for chaining.
This value cannot be null.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-02-13 UTC.