Wow, you boys made me realize how little I know, and now I'm even starting
to doubt my prior understanding. Can you please help me clarify the
following.
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?
Second, if this is the case, how do you actually create a shared bean and
why would you want one ?
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 ?
Sorry for these seemingly basic questions but I'm going through one of those
stages where I question the fundamental understanding. I must go read the
servlet API I think.
Soefara.
>From: Daniel Hinojosa <[EMAIL PROTECTED]>
>Reply-To: "Tomcat Users List" <[EMAIL PROTECTED]>
>To: Tomcat Users List <[EMAIL PROTECTED]>
>Subject: Re: Multiple users share java bean?
>Date: Mon, 25 Mar 2002 15:58:20 -0700
>
>In that case I recommend a facade bean in order to do this....
>
>For example, doing this.
>
>
>
>
>Chenming Zhao wrote:
>
>>Dniel,
>>
>>There is still one problem: the value set by the second user2 updated the
>>value of the first user1 before finishing user1's work. I paste the code.
>>Please take a look.
>>
>>public class test
>>{
>> int numEvents= 5;
>>
>> public synchronized int test()
>> {
>> int real=0;
>> int eventCounter=0;
>>
>> while(eventCounter<=numEvents)
>> {
>> real=eventCounter;
>>
>> // wait for 0.01 second
>> try{wait(10);}
>> catch(InterruptedException e){};
>> eventCounter++;
>> }
>> return real;
>> }
>>
>> public synchronized int setNumEvents(int sec)
>> {
>> numEvents= sec;
>> }
>>}
>>
>>For example, I input 200 as the value of numEvents for user1. Before
>>finishing user1's task, user2 input 100 as numEvents and begin his work.
>>I
>>hope I can get results 200 and 100 respectively. But I got 100 both.
>>
>>----- Original Message -----
>>From: "Daniel Hinojosa" <[EMAIL PROTECTED]>
>>To: "Tomcat Users List" <[EMAIL PROTECTED]>
>>Sent: Monday, March 25, 2002 11:35 AM
>>Subject: Re: Multiple users share java bean?
>>
>>>If it's a shared bean, sycnchronize it. Make sure that
>>>all mutators(Setters) are synchronized, and it would be a bad idea to do
>>>that to the
>>>accessors (mututors) are synchronized too. If you have more open than
>>>private member variables in this bean, make sure they are private.
>>>e.g.
>>>
>>>public void synchronized setName(String name) {
>>> .....
>>>}
>>>
>>>--
>>>Daniel Hinojosa
>>>
>>
>>
>>--
>>To unsubscribe: <mailto:[EMAIL PROTECTED]>
>>For additional commands: <mailto:[EMAIL PROTECTED]>
>>Troubles with the list: <mailto:[EMAIL PROTECTED]>
>>
>>
>>
>public class TestFacade {
> private Test test = null;
> public void synchronized process() {
> if (test == null) test = new Test();
> test.test();
> test.setNumEvents(2);
> }
>}
>
>
>With this I am pretty sure that you can take the synchronized off of
>methods of the Test Object and always use this testFacade before using
>your test object.
>
>Hope that helps
>
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
--
To unsubscribe: <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>