How to create request safe class or class property
<p>I will try to be short and most specific. It is possible to create class, class property or "something" which will be created for each request ? I mean something what will not be persistent for whole container (static class property).</p>

<p>I need to store internal identifier into class or property, which will be diferent for each request and persistent for whole request. I'm using java filters and before doFilter I need to save that identifier "somewhere". Because I need to use that identifier in application for some operations. And after doFilter I need to take that identifier from "somewhere" and update some other things.</p>

<p>Thanks for any advice how to solve this problem ...</p>

<hr>

<p>Edited 24th May 2011 10:25 am </p>

<p>Ok, I will try to explain my problem closely.</p>

<p>I'm using Tomcat 6 with BlazeDS utils. This server is working as backend for a flex application. 
So, if I want to send some messages or object or whatever else to server I just call something like this:</p>

<pre><code>service.doSomethingWithThis( data )
</code></pre>

<p>In flex is the "service" property mapped to class, eq. "foo.bar.BazService" and this service has method "doSomethingWithThis" with parameter "data". And when request is recieved by server then "doSomethingWithThis" method is executed with parameter "data".</p>

<pre><code>public int doSomethingWithThis( Object data ) {
  GenericDAO genDao = new GenericDao();
  genDao.create( data );
}
</code></pre>

<p>So, as you can see, I don't have access to the request property. What I call at Flex side it is called on Java side.</p>

<p>Another problem is with that DAO object (in this case GenericDAO). Those DAO objects are little bit specific. They are asking for database connection and this connection is provided by a singleton Class, which holds database connection for the whole application. So, I'm not passing connection parameter to DAO objects as is usual, but they are asking for that connection themselves. I know that it is not the right approach :).</p>

<p>Now we are trying to fix this problem and we want to use pooling database connection, which is provided by Tomcat. And there is problem. If I retrieve connection I need that connection put back to the pool. But my DAO objects are not closing database connection. Solution can be to pass connection parameter to DAO objects when service method is called and at the end close that connection, but I have a lot of services and it is a lot of refactoring. So I'm trying to find an another way, when I will be able to encapsulate whole request (Java Filters) and store database connection "somewhere". And my DAO Object can take this connection from "somewhere" place. </p>

<p>Store database connection in request is one solution, but as you can see, I don't know how to access this request in my DAO classes, or service classes. Other way is to use session, but there is also problem. There can be multiple requests to server and first request which will be completed will close that connection. So, other requests can not use that database connection anymore, because it was returned to pool.</p>

<p>So I'm targeting for solution, when I will be able to get one database connection for the whole request.</p>
