-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Alexis,
On 8/21/2011 10:16 AM, alexis wrote: > public class Queue { > > private static org.apache.log4j.Logger log = > Logger.getLogger(Queue.class); private Command command; private > boolean valueSet = false; So, a single-item queue? I think that has a different name... > public synchronized void put(Command c) { if (valueSet) { As Felix suggested, while() is usually better than if() in these cases. > try { wait(); } catch (InterruptedException ie) { } } this.command > = c; > > log.info("put : "+c.getCommand()); valueSet = true; notify(); } > > public synchronized Command get() { if (!valueSet) { try { wait(); > } catch (InterruptedException ie) { } } valueSet = false; > notify(); Why notify() here? > log.info("get : "+this.command.getCommand()); return command; What about setting "command" to null? That seems to be more in-line with the expected operation of this class. You can also use the null-ness of the "command" as your check instead of having the "valueSet" member (unless you want to be able to store nulls in your "queue"). Finally... why implement your own queue? Java comes with java.util.BlockingQueue which should probably meet your needs. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk5ScngACgkQ9CaO5/Lv0PA6nwCgvKvoe/vQaIXoTX9NN3ezOsPg I9AAoJirNl8Qz7MaGFbHTwjQ2zlrVn4i =XExe -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org