Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6751
| From | markspace <-@.> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: data shared between threads and synchronized on different objects |
| Date | 2011-08-02 08:54 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <j196k5$scp$1@dont-email.me> (permalink) |
| References | <8ac6f882-278b-46ab-a611-70130666c324@l37g2000yqd.googlegroups.com> |
On 8/2/2011 8:06 AM, Marcin Rodzik wrote: > - due to discovering that the queue (line 19) is empty the output > stream is flushed > - during flush some objects are added to the queue and flag I didn't look at your code, but this shouldn't be a problem. What kind of queue are you using? You should be using something like BlockingQueue. <http://download.oracle.com/javase/6/docs/api/java/util/concurrent/BlockingQueue.html> 1. Poll the queue, send if not empty; repeat until empty. 2. If empty, flush 3. After flushing, block on the queue. When new items are added, you'll wake up. You'll also wake up right away if some item was added to the queue in the meantime. That's it. Once you have a correctly synchronized queue, all the worries go away. If you can't use BlockingQueue for some reason, then you should code an object that works like it yourself. It shouldn't be terribly difficult.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
data shared between threads and synchronized on different objects Marcin Rodzik <marteno_rodia@o2.pl> - 2011-08-02 08:06 -0700 Re: data shared between threads and synchronized on different objects markspace <-@.> - 2011-08-02 08:54 -0700
csiph-web