Re: AW: Multiple users share java bean?
You guys are confusing me... At 10:52 27/03/2002 +0100, you wrote: Great, that's what I thought. But here's why I'm getting confused. The servlet tutorial says that a servlet is created once and once only (that's when the init() is run). http://java.sun.com/docs/books/tutorial/servlets/lifecycle/index.html If the servlet class is created only once, how does Tomcat then create multiple instances of the class ? In that case, I think Sun might be right ;-) As I said, I have never done servlets, the above is just what I suspected... Yes, this had alarm bells ringing for me - I'm pretty sure the tutorial is correct. As I understand it, each user request is serviced by a thread and these threads will all access the *same* instance of the class - this is precisely why we have to be careful of threading issues and use synchronised code blocks. From the tutorial: HTTP servlets are typically capable of serving multiple clients concurrently. If the methods in your servlet that do work for clients access a shared resource, then you can handle the concurrency by creating a servlet that handles only one client request at a time. (You could also synchronize access to the resource, a topic that is covered in this tutorial's lesson on threads.) To have your servlet handle only one client at a time, have your servlet implement the SingleThreadModelinterface in addition to extending the HttpServlet class. Various scoping mechanisms, such as those pointed out for beans, are available through various user, request, session and application data structures - see my book suggestions below. Eric wrote: If I comment out the init() method in my servlet do I get an instance of it for each request? Do people commonly do this? I suspect that if you do this Eric, it won't compile... If you'd prefer books written in English, I'd suggest you could do a lot worse than Hunter Crawford's Java Servlet Programming (2nd ed) from O'Reilly. As usual for O'R, its about as good a text as you'll get for the big picture and covers thread basics. More 'heavy duty' concurrency stuff (though not specifically related to servlets), based upon his book 'Concurrent Programming - the Java Programming Language' is available from Steven Hartley's site: http://www.mcs.drexel.edu/~shartley/ConcProgJava/ HTH cam __ Do You Yahoo!? Yahoo! Movies - coverage of the 74th Academy Awards® http://movies.yahoo.com/ -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: AW: Multiple users share java bean?
First of all, thank you so much Alexander for taking the time to explain this so thoroughly. First, am I correct in saying that the default behaviour for a Javabean is that each servlet or JSP that uses it will create a new instance of that Javabean ? For example, if we have Register.jsp which uses a Javabean called memberData.java then if 2 people were to submit data to Register.jsp at exactly the same time, each page would actually create and use a separate instance of the bean memberData.java. Is this correct? Nice answer: That depends :-) a) jsp:useBean id=mb class=MyBean scope=page / The bean is created for exactly this page executed by this user b) jsp:useBean id=mb class=MyBean scope=request / The bean is created for this page and all pages you jsp:include in this request. c) jsp:useBean id=mb class=MyBean scope=session / The bean is created and accessible by all pages of this application (You must include this line into all pages) p.ex.: You create a session bean that accesses a database. The database connection will be made once and will stand until the session runs out. There is a seperate bean for every user, though. d) jsp:useBean id=mb class=MyBean scope=application / The bean is created the first time a user accesses a page in your application. From then on, every user and every page will have the same bean! Lovely concise answer. I've printed this out as a cheat sheet :-) Now, since each JSP is essentially a servlet, how does the servlet perform the sharing of the javabean ? Does a servlet that shares a javabean (similar to the JSP case [d] above, where scope=application), is actually creating the javabean as a *static* variable so that it is shared by all members of the class ? Third, I'm getting confused and starting to doubt my understanding of servlets within the Tomcat servlet container. If we have a simple servlet using the helloWorld.class and it just prints hello world to the web page, then if 10 people were to requsest the servlet at the same time, am I correct in assuming that 10 different instances of the class are created to handle these requests ? true Great, that's what I thought. But here's why I'm getting confused. The servlet tutorial says that a servlet is created once and once only (that's when the init() is run). http://java.sun.com/docs/books/tutorial/servlets/lifecycle/index.html If the servlet class is created only once, how does Tomcat then create multiple instances of the class ? I could recommend a german book here, but I think that wouldn't be of great use for you... Good guess. Learning German through Java would surely be a challenge :) Thank you again, Soefara. _ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: AW: Multiple users share java bean?
One common technique to solve this is to use JMS. All beans that are instances of the same user listen to the same topic. when one instance of the user's bean is updated, the other instances are notified. Each bean then goes to the database to refresh itself. peter lin Chenming Zhao wrote: In fact, it's a good and difficult topic. Now I haven't still understood it completely. I have a question about my application. I describe the work what I need to finish. First the jsp file gets a user name, then pass it to java bean. And the bean get some values from the database accoding to the user name, then get a result and save it to database. The idea of synchronized objects cannot work. I want to acitvate independent instance of java bean for any user. How can I do? Is there any good book or material? Or maybe you can show me some simple example? Thanks. -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: AW: Multiple users share java bean?
What's the meaning of JMS? I'm not sure my problem is just what you said. I want to get independent instance or the same bean for each user. So they can work independently, and won't influence with each other. Thanks. - Original Message - From: peter lin [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 1:32 PM Subject: Re: AW: Multiple users share java bean? One common technique to solve this is to use JMS. All beans that are instances of the same user listen to the same topic. when one instance of the user's bean is updated, the other instances are notified. Each bean then goes to the database to refresh itself. peter lin Chenming Zhao wrote: In fact, it's a good and difficult topic. Now I haven't still understood it completely. I have a question about my application. I describe the work what I need to finish. First the jsp file gets a user name, then pass it to java bean. And the bean get some values from the database accoding to the user name, then get a result and save it to database. The idea of synchronized objects cannot work. I want to acitvate independent instance of java bean for any user. How can I do? Is there any good book or material? Or maybe you can show me some simple example? Thanks. -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: AW: Multiple users share java bean?
JMS - Javs Messaging Service Chenming Zhao wrote: What's the meaning of JMS? I'm not sure my problem is just what you said. I want to get independent instance or the same bean for each user. So they can work independently, and won't influence with each other. Thanks. - Original Message - From: peter lin [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 1:32 PM Subject: Re: AW: Multiple users share java bean? One common technique to solve this is to use JMS. All beans that are instances of the same user listen to the same topic. when one instance of the user's bean is updated, the other instances are notified. Each bean then goes to the database to refresh itself. peter lin Chenming Zhao wrote: In fact, it's a good and difficult topic. Now I haven't still understood it completely. I have a question about my application. I describe the work what I need to finish. First the jsp file gets a user name, then pass it to java bean. And the bean get some values from the database accoding to the user name, then get a result and save it to database. The idea of synchronized objects cannot work. I want to acitvate independent instance of java bean for any user. How can I do? Is there any good book or material? Or maybe you can show me some simple example? Thanks. -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: AW: Multiple users share java bean?
Are you sure you really want independent instances of the bean, or just the ability to keep the variable values separate by user? If it is the latter, then just use local variables in your bean methods. -Original Message- From: Chenming Zhao [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 2:06 PM To: Tomcat Users List Subject: Re: AW: Multiple users share java bean? What's the meaning of JMS? I'm not sure my problem is just what you said. I want to get independent instance or the same bean for each user. So they can work independently, and won't influence with each other. Thanks. - Original Message - From: peter lin [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 1:32 PM Subject: Re: AW: Multiple users share java bean? One common technique to solve this is to use JMS. All beans that are instances of the same user listen to the same topic. when one instance of the user's bean is updated, the other instances are notified. Each bean then goes to the database to refresh itself. peter lin Chenming Zhao wrote: In fact, it's a good and difficult topic. Now I haven't still understood it completely. I have a question about my application. I describe the work what I need to finish. First the jsp file gets a user name, then pass it to java bean. And the bean get some values from the database accoding to the user name, then get a result and save it to database. The idea of synchronized objects cannot work. I want to acitvate independent instance of java bean for any user. How can I do? Is there any good book or material? Or maybe you can show me some simple example? Thanks. -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: AW: Multiple users share java bean?
I misunderstood. You want many users to use the same bean to get common information, kind of like a message board. each user works independently, but they are using a common bean. someone else said If it is the latter, then just use local variables in your bean methods. more information about the requirements would help. there are a variety of ways to solve this type of problem, but they depend on the kind of persistence required. If they never get persisted, than anything old bean will do. peter lin Chenming Zhao wrote: What's the meaning of JMS? I'm not sure my problem is just what you said. I want to get independent instance or the same bean for each user. So they can work independently, and won't influence with each other. Thanks. - -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: AW: Multiple users share java bean?
Referring to this point: Great, that's what I thought. But here's why I'm getting confused. The servlet tutorial says that a servlet is created once and once only (that's when the init() is run). If I comment out the init() method in my servlet do I get an instance of it for each request? Do people commonly do this? -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: AW: Multiple users share java bean?
- Original Message - From: Wagoner, Mark [EMAIL PROTECTED] To: 'Tomcat Users List' [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 2:12 PM Subject: RE: AW: Multiple users share java bean? Are you sure you really want independent instances of the bean, or just the ability to keep the variable values separate by user? If it is the latter, then just use local variables in your bean methods. It seems that couldn't work. The value of such variables can be updated by another user's when there are two or more users calling the same java bean almost at the same time. Here is my main work. First jsp write uname (when a user login the website, there is a user name uname) to the bean and activate it, and get the result or save it to the database. Jsp file: jsp:useBean id=mb class=mybean.test scope=page / ???How about the scope value? session or request or page? jsp:setProperty name=mb property=uname value=%=loginname) %/ pThe result is: %= mb.test() %/p Bean code: public class test { String uname= ; public synchronized int test() { int real=0; int eventCounter=0; int numEvents; // connect to the database and get the numEvents according to the uname. .; while(eventCounter=numEvents) { real=eventCounter; // wait for 0.01 second try{wait(10);} catch(InterruptedException e){}; eventCounter++; } return real; } public synchronized void setUname(String sec) { uname= sec; } } For user1, numEvents=100; and user2, it's 120. So I want to run them at the same time, and hope to get resuls 100 and 120 respectively. But in fact I got both 100 or 120. Have any idea? If my description is not clear, tell me please. -Original Message- From: Chenming Zhao [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 2:06 PM To: Tomcat Users List Subject: Re: AW: Multiple users share java bean? What's the meaning of JMS? I'm not sure my problem is just what you said. I want to get independent instance or the same bean for each user. So they can work independently, and won't influence with each other. Thanks. - Original Message - From: peter lin [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 1:32 PM Subject: Re: AW: Multiple users share java bean? One common technique to solve this is to use JMS. All beans that are instances of the same user listen to the same topic. when one instance of the user's bean is updated, the other instances are notified. Each bean then goes to the database to refresh itself. peter lin Chenming Zhao wrote: In fact, it's a good and difficult topic. Now I haven't still understood it completely. I have a question about my application. I describe the work what I need to finish. First the jsp file gets a user name, then pass it to java bean. And the bean get some values from the database accoding to the user name, then get a result and save it to database. The idea of synchronized objects cannot work. I want to acitvate independent instance of java bean for any user. How can I do? Is there any good book or material? Or maybe you can show me some simple example? Thanks. -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: AW: Multiple users share java bean?
Are your sure loginname is getting set properly? Try including the value in your JSP output (right before the call to mb.test()) just to make sure. -Original Message- From: Chenming Zhao [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 3:05 PM To: Tomcat Users List Subject: Re: AW: Multiple users share java bean? - Original Message - From: Wagoner, Mark [EMAIL PROTECTED] To: 'Tomcat Users List' [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 2:12 PM Subject: RE: AW: Multiple users share java bean? Are you sure you really want independent instances of the bean, or just the ability to keep the variable values separate by user? If it is the latter, then just use local variables in your bean methods. It seems that couldn't work. The value of such variables can be updated by another user's when there are two or more users calling the same java bean almost at the same time. Here is my main work. First jsp write uname (when a user login the website, there is a user name uname) to the bean and activate it, and get the result or save it to the database. Jsp file: jsp:useBean id=mb class=mybean.test scope=page / ???How about the scope value? session or request or page? jsp:setProperty name=mb property=uname value=%=loginname) %/ pThe result is: %= mb.test() %/p Bean code: public class test { String uname= ; public synchronized int test() { int real=0; int eventCounter=0; int numEvents; // connect to the database and get the numEvents according to the uname. .; while(eventCounter=numEvents) { real=eventCounter; // wait for 0.01 second try{wait(10);} catch(InterruptedException e){}; eventCounter++; } return real; } public synchronized void setUname(String sec) { uname= sec; } } For user1, numEvents=100; and user2, it's 120. So I want to run them at the same time, and hope to get resuls 100 and 120 respectively. But in fact I got both 100 or 120. Have any idea? If my description is not clear, tell me please. -Original Message- From: Chenming Zhao [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 2:06 PM To: Tomcat Users List Subject: Re: AW: Multiple users share java bean? What's the meaning of JMS? I'm not sure my problem is just what you said. I want to get independent instance or the same bean for each user. So they can work independently, and won't influence with each other. Thanks. - Original Message - From: peter lin [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 1:32 PM Subject: Re: AW: Multiple users share java bean? One common technique to solve this is to use JMS. All beans that are instances of the same user listen to the same topic. when one instance of the user's bean is updated, the other instances are notified. Each bean then goes to the database to refresh itself. peter lin Chenming Zhao wrote: In fact, it's a good and difficult topic. Now I haven't still understood it completely. I have a question about my application. I describe the work what I need to finish. First the jsp file gets a user name, then pass it to java bean. And the bean get some values from the database accoding to the user name, then get a result and save it to database. The idea of synchronized objects cannot work. I want to acitvate independent instance of java bean for any user. How can I do? Is there any good book or material? Or maybe you can show me some simple example? Thanks. -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
Re: AW: Multiple users share java bean?
In fact I output the loginname. But here, when the problem happened, still the loginname was updated. So the problem is that the loginname was updated, then the username cannot get the right value. But when I tested it on different computer, it's correct. So I wonder why there is the problem when I open windows for multiple users. Is it the problem of the server or setting? - Original Message - From: Wagoner, Mark [EMAIL PROTECTED] To: 'Tomcat Users List' [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 3:28 PM Subject: RE: AW: Multiple users share java bean? Are your sure loginname is getting set properly? Try including the value in your JSP output (right before the call to mb.test()) just to make sure. -Original Message- From: Chenming Zhao [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 3:05 PM To: Tomcat Users List Subject: Re: AW: Multiple users share java bean? - Original Message - From: Wagoner, Mark [EMAIL PROTECTED] To: 'Tomcat Users List' [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 2:12 PM Subject: RE: AW: Multiple users share java bean? Are you sure you really want independent instances of the bean, or just the ability to keep the variable values separate by user? If it is the latter, then just use local variables in your bean methods. It seems that couldn't work. The value of such variables can be updated by another user's when there are two or more users calling the same java bean almost at the same time. Here is my main work. First jsp write uname (when a user login the website, there is a user name uname) to the bean and activate it, and get the result or save it to the database. Jsp file: jsp:useBean id=mb class=mybean.test scope=page / ???How about the scope value? session or request or page? jsp:setProperty name=mb property=uname value=%=loginname) %/ pThe result is: %= mb.test() %/p Bean code: public class test { String uname= ; public synchronized int test() { int real=0; int eventCounter=0; int numEvents; // connect to the database and get the numEvents according to the uname. .; while(eventCounter=numEvents) { real=eventCounter; // wait for 0.01 second try{wait(10);} catch(InterruptedException e){}; eventCounter++; } return real; } public synchronized void setUname(String sec) { uname= sec; } } For user1, numEvents=100; and user2, it's 120. So I want to run them at the same time, and hope to get resuls 100 and 120 respectively. But in fact I got both 100 or 120. Have any idea? If my description is not clear, tell me please. -Original Message- From: Chenming Zhao [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 2:06 PM To: Tomcat Users List Subject: Re: AW: Multiple users share java bean? What's the meaning of JMS? I'm not sure my problem is just what you said. I want to get independent instance or the same bean for each user. So they can work independently, and won't influence with each other. Thanks. - Original Message - From: peter lin [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 1:32 PM Subject: Re: AW: Multiple users share java bean? One common technique to solve this is to use JMS. All beans that are instances of the same user listen to the same topic. when one instance of the user's bean is updated, the other instances are notified. Each bean then goes to the database to refresh itself. peter lin Chenming Zhao wrote: In fact, it's a good and difficult topic. Now I haven't still understood it completely. I have a question about my application. I describe the work what I need to finish. First the jsp file gets a user name, then pass it to java bean. And the bean get some values from the database accoding to the user name, then get a result and save it to database. The idea of synchronized objects cannot work. I want to acitvate independent instance of java bean for any user. How can I do? Is there any good book or material? Or maybe you can show me some simple example? Thanks. -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED] -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto
Re: AW: Multiple users share java bean?
Chenming Zhao elucidated: In fact I output the loginname. But here, when the problem happened, still the loginname was updated. So the problem is that the loginname was updated, then the username cannot get the right value. But when I tested it on different computer, it's correct. ^^ So I wonder why there is the problem when I open windows for multiple users. This is just a guess, but try using two separate browsers (ergo, Netscape and Opera) on the same machine, too. Looking at your code, it is not clear whether numEvents is coming from some database owned by the server or from a variable in the browser's environment. I'm not sure what the terminology in Tomcat/JSP, but the environment variables from the browser are not necessarily flushed unless you shut the browser application program itself down. It's not even good enough to close one window if you have other windows of the same browser open. Since you are trying to access simultaneously, there is no way you would be able to shut the browser down before logging in as the second user. Browsers don't know much about sessions except for the cookie or query part of the URL in the link that the server might build. HTH. Joel Rees Alps Giken Kansai Systems Develoment Suita, Osaka Is it the problem of the server or setting? - Original Message - From: Wagoner, Mark [EMAIL PROTECTED] To: 'Tomcat Users List' [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 3:28 PM Subject: RE: AW: Multiple users share java bean? Are your sure loginname is getting set properly? Try including the value in your JSP output (right before the call to mb.test()) just to make sure. -Original Message- From: Chenming Zhao [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 3:05 PM To: Tomcat Users List Subject: Re: AW: Multiple users share java bean? - Original Message - From: Wagoner, Mark [EMAIL PROTECTED] To: 'Tomcat Users List' [EMAIL PROTECTED] Sent: Tuesday, March 26, 2002 2:12 PM Subject: RE: AW: Multiple users share java bean? Are you sure you really want independent instances of the bean, or just the ability to keep the variable values separate by user? If it is the latter, then just use local variables in your bean methods. It seems that couldn't work. The value of such variables can be updated by another user's when there are two or more users calling the same java bean almost at the same time. Here is my main work. First jsp write uname (when a user login the website, there is a user name uname) to the bean and activate it, and get the result or save it to the database. Jsp file: jsp:useBean id=mb class=mybean.test scope=page / ???How about the scope value? session or request or page? jsp:setProperty name=mb property=uname value=%=loginname) %/ pThe result is: %= mb.test() %/p Bean code: public class test { String uname= ; public synchronized int test() { int real=0; int eventCounter=0; int numEvents; // connect to the database and get the numEvents according to the uname. .; while(eventCounter=numEvents) { real=eventCounter; // wait for 0.01 second try{wait(10);} catch(InterruptedException e){}; eventCounter++; } return real; } public synchronized void setUname(String sec) { uname= sec; } } For user1, numEvents=100; and user2, it's 120. So I want to run them at the same time, and hope to get resuls 100 and 120 respectively. But in fact I got both 100 or 120. Have any idea? If my description is not clear, tell me please. -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]