Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7773107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:02:59+00:00 2026-06-01T17:02:59+00:00

Servlet API says about AsyncContext.start: void start(java.lang.Runnable run) Causes the container to dispatch a

  • 0

Servlet API says about “AsyncContext.start”:

void start(java.lang.Runnable run)

Causes the container to dispatch a thread, possibly from a managed thread pool, to run the specified Runnable. The container may propagate appropriate contextual information to the Runnable.

From this description it’s not clear how does it relate to task of optimizing thread usage when job requires waiting.

In “Servlet & JSP”, Budi Kurniawan gives example of Servlet 3.0 async features, where he uses AsyncContext.start, I’ll show simplified version of the example:

public void doGet(...) {
    final AsyncContext asyncContext = request.startAsync();

    asyncContext.start(new Runnable() {                        
        @ Override
        public void run() {
            // do some work here which involves waiting
            ...
            asyncContext.complete();
        }
    });
}

In most other examples I’ve met, the service method just stores the AsyncContext somewhere and it’s processed somewhere else (eg. by a background thread). In this example it looks like the job is just passed to another thread, which completes the request. As I understand, now it’s simply the worker thread, which wastes time on waiting.

Do you actually gain something by passing the job (which involves waiting) from one thread to another? If not, then what’s the purpose of AsyncContext.start(...)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:03:01+00:00Added an answer on June 1, 2026 at 5:03 pm

    You found a poor example, IMHO. In fact I wasn’t even aware of AsyncContext.start() existence.

    I had a quick look at how Jetty and Tomcat implement this. In fact, they seem to have some thread pool that handles asynchronous invocations independently.

    Such usage of the API gives you nothing or very little. Instead of blocking the HTTP thread you are blocking some other thread pool. So I can imagine the application still accepts new connections, but the problem remains – the container can’t handle them all because that extra thread pool is still limited.

    The whole points of AsyncContext is the ability to handle more than one request by a single thread. Often you need only a single thread to handle thousands of asynchronous connections – e.g. when exactly one thread waits for data that is suppose to be broadcasted to several clients. Also see The Limited Usefulness of AsyncContext.start()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I receive this exception when I try to run a jar file java.lang.ClassNotFoundException: javax.servlet.Servlet
I just downloaded from: http://java.sun.com/products/servlet/download.html the Java(TM) Servlet API Specification Interface Classes 2.3 Inside
I have a java servlet api, that when requested, starts a live conversion of
Quoting Java Servlet API Spec : A client (e.g., a Web browser) accesses a
In the Java Servlet API, the only way to get the ServletContext is through
I am learning both AJAX and the Java Servlet API (well, Spring MVC, which
In the Java Servlet API, what is done to ensure that someone's session id
I'm having an issue using the Cookie class of the Servlet API 2.5 on
Possible Duplicate: Where are the request method constants in the Servlet API? I'm looking
In servlet 3.0 one can use startAsync to put long work in another thread,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.