Contact: Tel: 2726 - New Media Systems, 1st Floor South, Queens Walk Bo Xu, >>I think there are other ways to solve it : for example, often saving >>this field into >>a persistent media. But if I don't do it, can I be sure that I can >>trust this counter? This is my question about Servlet_thread-safety :-) >> >>If you don't think it is a problem(because we can solve it with >>other ways), then I agree with you. But I want to know if >>we can solve it only by Servlet:-) so I think it is a problem, >>and I need to ask this question to try to know the answer :-) >> >>If you can solve my problem only by Servlet , I will >>go to buy some very good CDs and send to you if >>you like, and thanks very much :-) I can see during the weekend you have learnt a lot, even changed your [...] style to *...*. I don't think anyone will be lucky to get the CD you promised, because I know by the fact that servlet alone (meaning without persistency) CAN NOT provide a true persistent counter. This is because the obvious reason that web server can be shut down and your servlet can be reloaded. Your counter variable (no matter if it is an instance variable or class variable) only has the maximum life span between the time the class is being loaded into memory, to the time the instance is garbage collected. However, if you are opt for the persistent solution, the safest way is to update the counter directly from the persistent media (ideally a database of some sort). That is, every time you need to increase the counter, increase it from the persistent media (with proper locking of course). This will GUARANTEE that the counter reflects the true value. This solution is designed for those who does not trust (or maybe just not sure) that a servlet has one and only one inctance. Another more elegent solution is to implement a counter JavaBean and load it into memory when the web server is started. Your servlet will simply access this bean instance to read/update the counter. This way you don't even need to worry about anything that you are not sure about servlet. There are many ways to ensure that the JavaBean instance is unique during the life span of the web server, and obviously you still need to implement the bean as a persistent object. Cheers, Charles Bo Xu <[EMAIL PROTECTED]> on 11/03/2000 05:59:53 PM To: [EMAIL PROTECTED] cc: (bcc: Charles Chen/YellowPages) From: Bo Xu <[EMAIL PROTECTED]>, 3 November 2000, 5:59 p.m. Re: Single Thread Model.. [Scanned by Yellow Pages PostMaster] Nic Ferrier wrote: > Why are these problems? ... //********************************************* Charles Chen wrote: > Contact: Tel: 2726 - New Media Systems, 1st Floor South, Queens Walk > > Hope I have copied your typing style right ;-) ... ok :-) I will try my best to improve my English and I will stop to use [...] immediately to let my email easily to be read :-) sorry for [...] :-) But I still have a question : If I have a int static class field whose default value is 0 in my Servlet class, and , I suppose I want to use it as a counter of all the client accessings to this Servlet class, so between the first accessing to I close the Servlet engine, can I always get the accessing times by this int static class field? is it very safe? I think there are other ways to solve it : for example, often saving this field into a persistent media. But if I don't do it, can I be sure that I can trust this counter? This is my question about Servlet_thread-safety :-) If you don't think it is a problem(because we can solve it with other ways), then I agree with you. But I want to know if we can solve it only by Servlet:-) so I think it is a problem, and I need to ask this question to try to know the answer :-) If you can solve my problem only by Servlet , I will go to buy some very good CDs and send to you if you like, and thanks very much :-) BTW, this problem is not in my work , I am a JMF developer , but I am very interested in it :-) If it is in my work, I will try to solve it by myself with other way :-) Thanks in advance! Bo Nov.03, 2000 ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
