Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-3314

Servlet3AsynchronousResponse allocates a new executor service for each response in J2SE

XMLWordPrintable

      We run RestEasy in a J2SE environment with our own embedded Jetty and Spring integration. While profiling, I noticed many thousands of threads being created. I looked at the stack trace of thread creation and it seems that the Servlet3AsyncHttpRequest.Servlet3ExecutionContext.Servlet3AsynchronousResponse constructor calls ContextualExecutors.scheduledThreadPool() to e.g. set a timeout. This tries to look up via JNDI, otherwise allocates a new pool. So, it seems that for every response where we enter asynchronous mode, a new thread pool is allocated.

       

       

      I tried to register an executor:
      new InitialContext().bind("java:comp/DefaultManagedScheduledExecutorService", scheduler);

      but found that by default J2SE does not have any InitialContext available. And, in fact, there's seemingly no useful implementation of it distributed either.

       

      It would be nice if it were possible to have control over, or at least have a shared, scheduled executor service that RestEasy server uses, when in an embedded context where JNDI is not a good option. Or, am I missing some reasonable way to get a "local" JNDI setup going? Thanks for any guidance here.

              jperkins-rhn James Perkins
              stevenschlansker Steven Schlansker (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: