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

-- 
Daniel Hinojosa
Java & XML: Consultant | Developer | Instructor
P.O. Box 4675
Albuquerque, NM 87196-4675
(505) 363-5832






--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to