> > I have a generic public class containing a Vector that implements
Runnable. I
> > then have a subclassed singleton that I getInstance() in a jsp page to
make
> > sure that the browser clients are all using the same Vector.

Vector is already synchronized, so there should be no problem with multiple
threads access the Vector while it is also being updated in your code.

> > public void run(){
> >
> >   runThread = true;
> >   try{
> >     synchronized(this) {
> >        while(runThread){
> >             Thread.sleep(4000);
> >             imageURLs.addElement("barley");
> >             notifyAll();
> >        }
> >      }
> >    } catch (Exception e){ }
> > }

> The Thread that is sleeping does NOT release the synchronized
> lock!  I don't think you need to synchronize this code at all.

He's probably right because Vector is already synchronized.  Also, the more
common look for this is NOT to call Thread.sleep() but to call wait() with
the timeout.  At least then your class will release its lock while waiting,
and will reacquire it when the wait is over.  By doing a sleep, you keep the
lock the entire time, so others would not be able to access any other
synchronized methods in your class.

David




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to