Over a million developers have joined DZone.
Silver Partner

Undocumented Oracle JVM HttpServer Properties

· Java Zone

The Java Zone is brought to you in partnership with JetBrains.  Learn about instant and clever code completion, on-the-fly code analysis and reliable refactoring tools with IntelliJ IDEA.

I have blogged before on the utility of the HttpServer provided with the Oracle HotSpot JVM. One of the general challenges associated with its use is the lack of documentation. Fortunately, its open source implementation allows certain features to be discovered. In this post, I look at some apparently undocumented properties that are used by the HttpServer's source code.

A colleague (thanks Jim!) pointed out the existence of these properties as discovered in the source code. There are multiple places from which the relevant source code can be acquired and reviewed. One easily accessible location is Docjar. For example, the code listings for sun.net.httpserver.ServerConfig and sun.net.httpserver.ServerImpl are hosted there. Other similar sites include Open Source Java Code (ServerConfig) and grepcode (ServerConfig).

The static initialization block of the sun.net.httpserver.ServerConfig class includes the setting of several static variables based on specific Java properties or based on a default if no property is provided. The next code listing comes from that class and indicates the default values for these static variables.

static final int DEFAULT_CLOCK_TICK = 10000 ; // 10 sec.

/* These values must be a reasonable multiple of clockTick */
static final long DEFAULT_IDLE_INTERVAL = 30 ; // 5 min
static final int DEFAULT_MAX_IDLE_CONNECTIONS = 200 ;

static final long DEFAULT_MAX_REQ_TIME = -1; // default: forever
static final long DEFAULT_MAX_RSP_TIME = -1; // default: forever
static final long DEFAULT_TIMER_MILLIS = 1000;

static final long DEFAULT_DRAIN_AMOUNT = 64 * 1024;

As the code and comments above indicate, the default idle interval is 300 seconds (5 minutes). The default request and response times are "forever" indicated by -1.

Although defaults are available as indicated in the above code listing, these can be overridden via the specification of Java properties. These properties are not well documented, but can be gleaned from the code. The following is a list of them as extracted from the ServerConfig class with notes about each property based on other portions of the code.

Properties for Configuring HotSpot HttpServer
  • sun.net.httpserver.idleInterval
  • sun.net.httpserver.clockTick
  • sun.net.httpserver.maxIdleConnections
  • sun.net.httpserver.drainAmount
  • sun.net.httpserver.maxReqTime
    • Replaces sun.net.httpserver.readTimeout
  • sun.net.httpserver.maxRspTime
    • Replaces sun.net.httpserver.writeTimeout
  • sun.net.httpserver.timerMillis
  • sun.net.httpserver.debug

Note that the property sun.net.httpserver.selCacheTimeout is no longer used, but does not have its replacement spelled out in the code comments or logged messages.

The Oracle JVM HttpServer allows for configuration based on Java properties. These properties are not well advertised, but the open source nature of the HttpServer implementation makes it possible to browse the code to determine which properties are available.



The Java Zone is brought to you in partnership with JetBrains.  Learn about instant and clever code completion, on-the-fly code analysis and reliable refactoring tools with IntelliJ IDEA.


Published at DZone with permission of Dustin Marx , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}