Thanks for your help.
Of course I want that multple users can use multiple instances of the bean.
But I don't know much about the instance. Can you explain or show me
something about it?
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Monday, March 25, 2002 2:29 PM
Subject: Re: Multiple users share java bean?
>
> If you have multiple users sharing the same bean, then that's what's going
to
> happen. By synchronizing the get and set method, all you're doing is
saying
> "Make sure the user finishes this whole get or set method before any other
> user can start it." However, that won't prevent another user from calling
the
> set method right after the first user does and before the first user has a
> chance to call the get method. Are you sure you want multiple users
sharing
> the same bean here? Or do you want multiple users using multiple
instances of
> the bean (what it sounds like to me)??
>
>
>
>
> "Chenming
> Zhao" To: "Tomcat Users List"
<[EMAIL PROTECTED]>
> <[EMAIL PROTECTED] cc:
> u> Subject: Re: Multiple users
share java bean?
>
> 03/25/02
> 12:52 PM
> Please
> respond to
> "Tomcat Users
> List"
>
>
>
>
>
>
> 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]>
>
>
>
>
>
>
> --
> 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]>