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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:10:49+00:00 2026-05-28T15:10:49+00:00

As part of exception handling, I want to print data from HTTP session like

  • 0

As part of exception handling, I want to print data from HTTP session like below:

try{  
    //business logic
} catch(Exception ex){
    String user = session.get("userId"); //get user from HTTP Session.
    log.info("Exception when processign the user "+user); 
}

My question is do I get the correct UserId for which exception occurred since there will be mulitple threads updating the session?

  • 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-28T15:10:50+00:00Added an answer on May 28, 2026 at 3:10 pm

    The HttpSession is not shared among clients. So that part is safe already. The remnant depends on your own code as to obtaining and handling the HttpSession instance. If you’re for example assinging the HttpSession as an instance variable of an application wide class, like the servlet itself, then it is indeed not thread safe as it might be overridden by another request at the moment you’re accessing it.

    public class SomeServlet extends HttpServlet {
    
        private HttpSession session;
    
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            session = request.getSession();
    
            // ...
    
            Object object = session.getAttribute("foo"); // Not threadsafe!
        }  
    

    See also:

    • How do servlets work? Instantiation, sessions, shared variables and multithreading
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to use an exception for error handling in a part of my
I try to put a exception logic which a part of a system can
I have a BizTalk (2006 R2) scope with a Catch Exception part in which
Im geting exception whene the code comes to this part : [GridAction] public JsonResult
It seems that this part of my code is where the exception occurs: c
Part of my web application is a background script that polls from a beanstalkd
Part of our website is protected with .htaccess style password protection. When you try
I have added try catches in my site which work great. The next part
After going through some links on exception handling ( 1 , 2 , and
I am working on my first major PHP/MySQL application. I use the Exception handling

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.