Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33122
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2015-11-13 07:29 -0800 |
| References | <n24r35$f4s$1@dont-email.me> |
| Message-ID | <26941c4f-9360-4dae-874e-56413cfb8a36@googlegroups.com> (permalink) |
| Subject | Re: To BlockingQueue or not to BlockingQueue? |
| From | Eric Douglas <e.d.programmer@gmail.com> |
On Friday, November 13, 2015 at 9:14:24 AM UTC-5, Eric Sosman wrote: > Short version: I wrote a simple submit-tasks-and-reap-results > class based on a ThreadPoolExecutor. Initially it seemed I could > use an ExecutorCompletionService to manage the flow of work, but > that didn't pan out. Then I tried having the tasks place their own > results on a BlockingQueue explicitly, but that didn't pan out either. > Eventually, I retrogressed all the way to using an ordinary Queue and > an old-fashioned synchronized/wait/notifyAll scheme. I'm hoping for > some hints about how to use the java.util.concurrent classes better, > since they're more modern and fashionable. I'm certainly no expert on concurrency, and the only queue I've had to reference was EventQueue.invokeLater() to kick off a GUI screen (appears to do the same as SwingUtilities.invokeLater()?), but I did recently write a multithreaded method if it helps. I needed to call a method from the Google API, which goes out to the web so it could take a minute, without the GUI thread showing unresponsive. So I created a Semaphore and assigned it 1 permit, then acquired a permit, then created a SwingWorker which creates a new thread on the doInBackground() which releases a permit when it's done. Then I call the worker.execute(), then the semaphore.tryAcquire(), then the worker.get(). I don't know if this is proper or most efficient but it appears to be working. You can set a timeout on the acquire methods, and they throw InterruptedException if your current thread is aborted.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
To BlockingQueue or not to BlockingQueue? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-13 09:13 -0500
Re: To BlockingQueue or not to BlockingQueue? Eric Douglas <e.d.programmer@gmail.com> - 2015-11-13 07:29 -0800
Re: To BlockingQueue or not to BlockingQueue? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-13 10:41 -0500
Re: To BlockingQueue or not to BlockingQueue? Eric Douglas <e.d.programmer@gmail.com> - 2015-11-13 07:57 -0800
Re: To BlockingQueue or not to BlockingQueue? Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2015-11-13 16:56 -0800
Re: To BlockingQueue or not to BlockingQueue? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-14 17:08 -0500
Re: To BlockingQueue or not to BlockingQueue? Arne Vajhøj <arne@vajhoej.dk> - 2015-11-13 21:40 -0500
Re: To BlockingQueue or not to BlockingQueue? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-14 17:24 -0500
Re: To BlockingQueue or not to BlockingQueue? Arne Vajhøj <arne@vajhoej.dk> - 2015-11-14 19:13 -0500
Re: To BlockingQueue or not to BlockingQueue? Steven Simpson <ss@my.domain.invalid> - 2015-11-15 10:37 +0000
Re: To BlockingQueue or not to BlockingQueue? Sebastian <news@seyweiler.dyndns.org> - 2015-11-16 01:00 +0100
csiph-web