com.sun.net.httpserver.HttpServer should accept a custom ThreadFactory to create its HTTP-Dispatcher thread

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P4
    • None
    • Affects Version/s: None
    • Component/s: core-libs
    • None

      My colleague Michael Vorburger reports:

      The JDK's HttpServer internally creates its "HTTP-Dispatcher" named thread, in the start() method of ServerImpl: https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java#L190

      This makes it difficult to have one's registered custom HttpHandler "propagate" something stored in a "parent" ThreadLocal - even if setting a customer Executor - that won't work because however such an executor is implemented, it itself runs under said "HTTP-Dispatcher" thread, which won't "see" a "parent" ThreadLocal.

      This issue suggests that HttpServer should accept a custom ThreadFactory to create its HTTP-Dispatcher thread, e.g. by adding a create(InetSocketAddress addr, int backlog, ThreadFactory threadFactory) method, in addition to the existing create(InetSocketAddress addr, int backlog) method on HttpServer (and then "piping it through", as required).

            Assignee:
            Michael McMahon
            Reporter:
            Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: