Speaking Java servlets here ... I'm working on creating my own "Per Request Context", and I was looking to bind the "Request Context" object to the value of Thread.currentThread (). getId ().
Instead of going around this context object everywhere, I planned to check the current thread when the user calls a function based on the request and automatically gets the Context object from the hash table for this threadId.
I would use code like this.
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
MyFramework.EnterContext();
try {
}
finally { MyFramework.ExitContext(); }
}
However, I would like to protect my application automatically from any potential user who does not call ExitContext (). In C # there is an event handler for the stream object for onexit ... (I think I'm wrong about this) is there a way to detect or poll when the stream exits? Currently I only save threadId (long).
Any ideas?
source
share