So know that I have two responses, one being to pass the object to other
methods and one being to use a syncronized block.

Lets start a discussion as to which is better?

Christopher T. Beers               Systems Analyst Administrator I
Office of Information Technology - Boston University
111 Cummington Street              (617)353-8248      
Boston, MA 02215                   (617)353-6260 fax


On Tue, 20 Jul 1999, Claude Zervas wrote:

> At 06:02 PM 7/20/99 +0200, you wrote:
> >
> >Hi Christopher,
> >On Tue, 20 Jul 1999, Christopher T. Beers wrote:
> >CTB|         I appreciate everyone help in this matter yesterday.  The porblem
> >CTB| was the scope of my doPost() method.  Outside of the method I declare
> >CTB| 
> >CTB| private Hashtable table = new Hashtable();
> >
> >You should never do this, because the doPost(), doGet() or
> >service()-Method could be called from several threads _in parallel_ which
> >means that your parameters could get munged if two peope connect to your
> >servlet. You've to make sure that your methods are reentrant.
> >
> >In order to get this save, initialize your Hashtable in the processing
> >method:
> >
> >  public void doPost (...) {
> >    Hashtable table = new Hashtable();
> >    .. do stuff
> >  }
> >  
> >If you need these parameters in other methods in your servlet (which is
> >what I assume you want do), you've to pass the table as parameter .. no
> >way around it ..
> 
> Yes there is, just put the usage in a synchronized block:
> 
>       synchronized ( table ) {
>               ....
>               table.put( obj );
>               ...
>       }
> 
> - Claude 
> 
> 
> --
> --------------------------------------------------------------
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> READ THE FAQ!!!!     <http://java.apache.org/faq/>
> Archives and Other:  <http://java.apache.org/main/mail.html/>
> Problems?:           [EMAIL PROTECTED]
> 



--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
READ THE FAQ!!!!     <http://java.apache.org/faq/>
Archives and Other:  <http://java.apache.org/main/mail.html/>
Problems?:           [EMAIL PROTECTED]

Reply via email to