Ryan Detert wrote:
>
> 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.
>
> I want to add an element to the Vector every 4 seconds using Thread.sleep(). I
> am trying to access this Vector in a jsp page by reloading the browser every 4
> seconds. The page is supposed to display the contents of the Vector. The
> generic class' run method is posted below.
>
> when I run this method the jsp page seems to be eternally hung. without the
> synchronized{} statement the Vector would get updated once and that would be
> all.
>
> public void run(){
>
> runThread = true;
> try{
> synchronized(this) {
> while(runThread){
> Thread.sleep(4000);
> imageURLs.addElement("barley");
> notifyAll();
> }
> }
> } catch (Exception e){ }
> }
>
> Anyone know why it doesn't seem to work?
>
> -thanx
> Ryan
The Thread that is sleeping does NOT release the synchronized
lock!
I don't think you need to synchronize this code at all.
--
WBB - [EMAIL PROTECTED]
Java Cert mock exams http://www.lanw.com/java/javacert/
Author of Java Developer's Guide to Servlets and JSP
ISBN 0-7821-2809-2
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]