Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 73935 invoked from network); 9 Feb 2004 19:55:03 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 9 Feb 2004 19:55:03 -0000 Received: (qmail 12430 invoked by uid 500); 9 Feb 2004 19:53:35 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 12381 invoked by uid 500); 9 Feb 2004 19:53:34 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 12184 invoked from network); 9 Feb 2004 19:53:33 -0000 Received: from unknown (HELO cardinal.mail.pas.earthlink.net) (207.217.121.226) by daedalus.apache.org with SMTP; 9 Feb 2004 19:53:33 -0000 Received: from user6.net868.va.sprint-hsd.net ([69.34.33.6] helo=ptslaptop) by cardinal.mail.pas.earthlink.net with smtp (Exim 3.33 #1) id 1AqHTD-0003cd-00 for tomcat-user@jakarta.apache.org; Mon, 09 Feb 2004 11:53:27 -0800 Message-ID: <005201c3ef46$67b218a0$7a01a8c0@ptslaptop> From: "Parsons Technical Services" To: "Tomcat Users List" References: <684843FCB39BE8408ACB559F7FFDD9FD4AA5A6@mail.kenexa.com> Subject: Re: Servlet thread safety in Tomcat Date: Mon, 9 Feb 2004 14:50:20 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Another approach is to have your application create an instance for each session that will retrieve the mail for that session. Just ensure that the resource you are accessing can handle it, or you will have problems either way. (Note I am approaching this from a programming view. I am not familar with JavaMail yet.) Not much different than what Albert proposes, just changes where you split the tree in the process. Doug Parsons www.parsonstechnical.com ----- Original Message ----- From: "Yu, Albert" To: "'Tomcat Users List'" Sent: Monday, February 09, 2004 2:23 PM Subject: RE: Servlet thread safety in Tomcat > > If you implement the SingleThreadModel interface for your Servlet class, > TomCat will create a new instance for each request. > > Albert > > -----Original Message----- > From: kwirirai [mailto:kwirirai@designat7.co.zw] > Sent: Monday, February 09, 2004 2:12 PM > To: Tomcat Users List > Subject: Re: Servlet thread safety in Tomcat > > But if I am to synchronise my code blocks won't that slow done the > application, or is there a "mode" that you can put Tomcat into so that > it will create a new instance > servlet thread with its own variables and execution space and stuff > like that .Because I was thinking putting all those synchronized blocks > will slow down the app. > > David Ramsey wrote: > > >Your primary mistake seems to be in assuming that Tomcat will create a > >new instance of a servlet for every thread started. This is not what > >happens, therefore servlet instance variables are not thread safe > >unless you take additional actions to make them safe. Likewise, > >application global entities, such as singletons, won't be thread safe > >without taking additional actions on your part. The short rule is > >simply if two threads might access this data concurrently, then you > >need to protect yourself from such a collision. About the only thing > >that is mostly thread safe are objects whose scope is limited to a > >single method, but even these can get you in trouble if you put > >references to those objects in global locations (such as an application > >wide cache). > > > > > >--- kwirirai wrote: > > > > > >>The app is simply meant to grab some mails from a pop server and > >>simply > >>display it using Java Mail. > >>I realise part of my mistake is using global variables > >>,unsynchronized > >>collections and unsynchronized code blocks.I am not using the single > >>thread model. > >>My initial thought ( :-) forgive me its some time since I have coded > >> > >>servlets) was that Tomcat will create a new servlet instance that is > >>totally independed of the other, for each request.On testing the app > >>on > >>two client machines I have realized that the data is corrupted all > >>mixed > >>up and my velocity template is throwing an error caused by > >>concurrent > >>modification. > >>My question is there some way of making this app thread safe and also > >> > >>how does Tomcat actually many requests , in terms of the threading > >>method used?I am using Tomcat 4.1 > >> > >> > >>Shapira, Yoav wrote: > >> > >> > >> > >>>Howdy, > >>>State your specific requirements and we can help you design > >>>servlets/objects that will meet those requirements. Your original > >>> > >>> > >>post > >> > >> > >>>is too broad to solicit a detailed response. > >>> > >>>Yoav Shapira > >>>Millennium ChemInformatics > >>> > >>> > >>> > >>> > >>> > >>> > >>>>-----Original Message----- > >>>>From: kwirirai [mailto:kwirirai@designat7.co.zw] > >>>>Sent: Monday, February 09, 2004 12:48 PM > >>>>To: tomcat-user@jakarta.apache.org > >>>>Subject: Servlet thread safety in Tomcat > >>>> > >>>>Hi All > >>>>I am developing an application that uses JavaMail.What I am > >>>> > >>>> > >>concered is > >> > >> > >>>>the issue of thread safety,and efficiency.My question is do I need > >>>> > >>>> > >>to > >> > >> > >>>>employ synchronized blocks in my Servlet code or is there another > >>>> > >>>> > >>way > >> > >> > >>>> > >>>> > >>>> > >>>> > >>>to > >>> > >>> > >>> > >>> > >>>>implement thread safety.I have been experimenting with the > >>>> > >>>> > >>application > >> > >> > >>>>and I have seen that the data is actualy mixing up.I realy need to > >>>> > >>>> > >>now > >> > >> > >>>>how Tomcat handles request and issues those request ,this is in > >>>>connection with threading. I have thought about the single thread > >>>> > >>>> > >>model > >> > >> > >>>>in my servlets but I think this is an inefficient method to use. > >>>> > >>>>Thanks > >>>>Kwiri > >>>> > >>>> > >>>> > >>>> > >>>> > >>>> > >>>--------------------------------------------------------------------- > >>> > >>> > >>>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > >>>>For additional commands, e-mail: > >>>> > >>>> > >>tomcat-user-help@jakarta.apache.org > >> > >> > >>>> > >>>> > >>>> > >>>> > >>> > >>> > >>>This e-mail, including any attachments, is a confidential business > >>> > >>> > >>communication, and may contain information that is confidential, > >>proprietary and/or privileged. This e-mail is intended only for the > >>individual(s) to whom it is addressed, and may not be saved, copied, > >>printed, disclosed or used by anyone else. If you are not the(an) > >>intended recipient, please immediately delete this e-mail from your > >>computer system and notify the sender. Thank you. > >> > >> > >>> > >>> > >>--------------------------------------------------------------------- > >> > >> > >>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > >>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org > >>> > >>> > >>> > >>> > >>> > >>> > >> > >> > > > > > >__________________________________ > >Do you Yahoo!? > >Yahoo! Finance: Get your refund fast by filing online. > >http://taxes.yahoo.com/filing.html > > > >--------------------------------------------------------------------- > >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org > > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org