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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:58:05+00:00 2026-06-17T15:58:05+00:00

While testing concurrent access in our web application we are having some difficulty tracing

  • 0

While testing concurrent access in our web application we are having some difficulty tracing session behavior.

Say we have three different users, A, B, and C.

We are logging in to the application with three different browsers with these three users then at run time my user object is changing from B to A or B to C or C to A, but this is happening randomly.

My UserContextHolder class is :

public final class UserObjContextHolder {
    private static final ThreadLocal<UserObj> CONTEXT_HOLDER = new ThreadLocal<UserObj>();

    private UserObjContextHolder() {
    }

    public static void setUserObj(UserObj userObj) {
        CONTEXT_HOLDER.set(userObj);
    }

    public static UserObj getUserObj() {
        return CONTEXT_HOLDER.get();
    }

}

I am using Hibernate for ORM and Spring MVC

Can anybody tell me reasons for this session behavior or how I can synchronize it?

I noticed one thing: if User A is logged in and doing some search operation and if User B logs in at the same time then userObj A is changing to userObj B.

Is it related to Application server setting? This happens only while doing authentication.

  • 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-17T15:58:05+00:00Added an answer on June 17, 2026 at 3:58 pm

    I would like to know more on how you have performed your search operation and at what point you have set the UserObj in your ThreadLocal object (CONTEXT_HOLDER).

    We must remember that ThreadLocal is thread scoped and not session scoped. This means that the set object in the ThreadLocal is the same if and only if the thread that set the object is the same as the thread who requested it.

    My initial theory would be the search operation is performed in the same session but not on the same thread. A simple scenario would like be below:

    • UserA logs in using Thread A. UserA is stored in the CONTEXT_HOLDER using Thread A.
    • UserB logs in using Thread B. UserB is stored in the CONTEXT_HOLDER using Thread B.
    • UserC logs in using Thread C. UserC is stored in the CONTEXT_HOLDER using Thread C.
    • After a while UserA performs search operation. Server executes the operation (luckily) using Thread A. ThreadLocal returns UserA obj which is correct and expected!
    • Again, after a while, User A performs search operation. This time, (unfortunately) the server executes the operation using Thread C (uh-oh!). ThreadLocal will return UserC since Thread C was used to execute the search operation. (On the other hand, if Thread B was used in the search operation, UserB will be returned by ThreadLocal)

    Above scenario was over-simplified, assuming only three threads are used by the server. But I do hope it explains how you are getting different UserObj objects.
    If what I described above is what you are experiencing, I think you are also receiving NULL values from time to time (frequency of this encountered depends on the total threads used by the server). The reason is that ThreadLocal returns the initial value if it is not currently set (which is null based on your code above).

    So a solution to your problem is to ensure you perform the following in the same thread:

    • Set UserObj in your ThreadLocal
    • Perform search operation and getting UserObj in your ThreadLocal

    If you wish I can give you a sample code for this, just let me know.

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

Sidebar

Related Questions

I found some problem while testing my NLP system. I have a java regex
I use Firefox in daily use. While testing own web-application in Internet Explorer, I've
I have been having a bit of a bug while testing on iOS 6
While stress testing prototype of our brand new primary system, I run into concurrent
I'm having trouble with logout() while testing my project with the Django web server.
I have a page that uses excanvas to draw some images. While testing the
My time zone is CET (Berlin). And while testing Joda's DateTime i noticed some
I am using Windows 2008 r2 64 bit system. While testing our script ,we
I get this error, while I'm testing the code below: You have an error
While testing some scripts, I've noticed, if expiration time is little (not zero) -

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.