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 6745717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:14:17+00:00 2026-05-26T12:14:17+00:00

This just came to mind when testing the Tomcat NIO connector during my load

  • 0

This just came to mind when testing the Tomcat NIO connector during my load tests. I make use of ThreadLocal’s additionally I use Spring, which I know in several places it also makes use of it.

Since the NIO connector does not have a thread per connection, I worry that it may result in very hard to find bugs if a ThreadLocal object was shared with another thread before it had been cleaned up. However, I assume that this is not an issue as it is not a documented warning that I could find, nor have I found any other posts warning about this. I assume that the NIO connector has no effect to the threads that serve the actual requests.

Before I go with this assumption, I was hoping to find some concrete proof.

  • 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-05-26T12:14:17+00:00Added an answer on May 26, 2026 at 12:14 pm

    Only someone familiar with the Tomcat code will be able to give you a concrete answer, but I’ll try a wooden one 🙂

    Firstly, you need to be clear whether you mean simply using NIO connectors or whether you’re also talking about Async servlets.
    The answer will be slightly different in each case.

    The main thing to be aware of is that Java doesn’t have any sort of continuations, co-routines or thread-rescheduling. Which means that once you launch a piece of code running on a thread, only that piece of code will run on the thread until it completes.

    So if you have: myObject.doSomething(); then for the time doSomething runs, it has exclusive access to that thread. The thread is not going to switch to some other piece of code – regardless of what sort of IO model you’re using.

    What might (will) happen is that different threads will be scheduled to run on different CPUs, but each thread will run one piece of code to completion.

    So if doSomething is:

    public static final ThreadLocal<MyClass> VALUE = new ThreadLocal<MyClass>();
    public void doSomething() {
      VALUE.set(this);
      try {
        doSomethingElse();
      } finally {
        VALUE.set(null);
      }
    }
    

    then there’s nothing to worry about – doSomethingElse will run one a single thread and the threadlocal will be set to the right value for the whole execution.

    So a simple NIO connector should make no difference – the container will call the service method on the servlet, the servlet will execute in a single thread, and then at the end it’s all done. It’s just that the container is able to process the IO in a more efficient way as it handles the connections.

    If you’re using async servlets then it’s a little different – in that case your servlet might get called multiple times for a single request (because of the way the asynchronous model works), and those calls might be on different threads, so you can’t store something in a thread-local between invocations of your servlet. But for a single call to your service method, it’s still fine.

    HTH.

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

Sidebar

Related Questions

I just came across a C++ SDK that makes heavy use of this really
This is not something most people would probably use, but it just came to
This question has just came in to my mind, and I'm not in a
I just came across this code and a few Google searches turn up no
I just came across this question about initializing local variables. Many of the answers
I just came over this syntax in some of the questions in this forum,
I just came across this idiom in some open-source Python, and I choked on
I just came a cross this nice code that makes this scatter matrix plot:
I just came up with this, it seems to work in all modern browsers,
Just came across this quote in a book on OOP that I'm reading, A

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.