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

  • Home
  • SEARCH
  • 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 4120490
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:13:44+00:00 2026-05-20T23:13:44+00:00

I have experimented the inconsistency when multiple threads access/modify context variables but could not

  • 0

I have experimented the inconsistency when multiple threads access/modify context variables but could not produce the same behaviour at session level. For example calling session.setAttribute(“something”) method within the service method does not cause race-condition when two requests (which means two threads) for same sessionid come in. Is it because Tomcat provides thread safety for session variables or I have got in completely wrong?

  • 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-20T23:13:45+00:00Added an answer on May 20, 2026 at 11:13 pm

    Servlet spec ver 3.0 explicitly states that access to session keys is thread-safe, in section 7.7.1.
    However, access to elements stored under these keys isn’t thread-safe. Thread safety in this case must be ensured by application developer.

    7.7.1 Threading Issues
    Multiple servlets executing request threads may have active access to the same
    session object at the same time. The container must ensure that manipulation of
    internal data structures representing the session attributes is performed in a thread
    safe manner. The Developer has the responsibility for thread safe access to the
    attribute objects themselves. This will protect the attribute collection inside the
    HttpSession object from concurrent access, eliminating the opportunity for an
    application to cause that collection to become corrupted.

    Sample code to illustrate this:

    HttpSession session;
    List items;
    session.put("cart", items); // thread1 writes cart reference to session, this is thread-safe
    ...
    items = session.get("cart"); // thread1 reads cart reference from session, this is thread-safe
    items.get(0); // access to elements of application collection is *not* thread-safe, you must use explicit synchronization here.
    

    I believe what is meant here by “thread safe manner” is that HttpSession access methods are guaranteed to be thread-safe, but all access to elements stored in session by methods of these elements is not guaranteed to be thread-safe.

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

Sidebar

Related Questions

I have experienced some memory managment ambiguitys with opencv. You could do this with
I have experimented with several different static analyzers for Java, notably Findbugs and PMD.
I'm new to SVN and have experimented with it locally on my Dreamhost test
I have enjoyed learning to use OpenGL under the context of games programming, and
I have experimented with this: >> code-block: copy [] == [] >> append code-block
I have experimented with a technique that involves a web page request which you
I would like app to add several (2k) words to UserDictionary. I have experimented
I am a noob to Python and have not had any luck figuring this
This is the first time I have experimented with the awesome Web Api and
Cross-posted from the Cukes Google Group: I have experimented with a number of methods

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.