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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:25:33+00:00 2026-06-02T17:25:33+00:00

Talking Java Servlets here… I’m working on creating my own Per Request Context and

  • 0

Talking Java Servlets here… I’m working on creating my own “Per Request Context” and I was looking to tie the “Per Request Context” object to the Thread.currentThread().getId() value.

Instead of passing around this context object everywhere I was planning on checking the current threadid when a user calls a function that is Per Request based and automatically getting the Context object out of a hashtable for that threadId.

I would use the code this like..

public void doPost(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException
{
    MyFramework.EnterContext();
    try {
        // do stuff here that leads to other classes on the same thread
        // Access current context via static MyFramework.getCurrentContext()
    }
    finally { MyFramework.ExitContext(); }
}

However I would like to protect my application automatically from any potential user that does not call ExitContext(). In C# there is an event handler on the thread object for onexit…(think I wrong on this) is there some way to detect or poll when a thread exits? I’m currently storing only the threadId (long).

Any ideas?

  • 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-02T17:25:35+00:00Added an answer on June 2, 2026 at 5:25 pm

    unfortunatelly, there is no such feature built in for threads in Java. Besides, thread id is only guaranteed to be unique at any one time, but may be reused eventually when the thread dies (from the docs). however, the servlet framework that you are using may be implementing such feature (just a speculation).

    i would recommend you implement a servlet filter, and tell your users to include it in their web.xml. with this you can be sure the client code always gets correctly wraped in your thread context.

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

Sidebar

Related Questions

Yes, I am talking about Java 1.3 - I'm maintaining an application that for
Talking about System.Collections.Generic.List<T> here. With example below can Method1 and Method2 execute and the
Is there anything that java cannot do? But other's can? I am talking about
I was talking with my teacher, and she mentioned that an object variable (she
I have a machine running a java app talking to a mysql instance running
I've seen people mention java and .net when talking about Cobol and haven't seen
I am trying to implement nodes talking to each other in Java. I am
I know that a semicolon is required after a statement (I'm talking about Java,
We are trying to get WCF and Java talking to each other using SAML
Does the Java compiler remove multiplications by 1, when talking about BigDecimal? I'm standing

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.