--
guava-...@googlegroups.com.
http://groups.google.com/group/guava-discuss?hl=en
unsubscribe: guava-discus...@googlegroups.com
This list is for discussion; for help, post to Stack Overflow instead:
http://stackoverflow.com/questions/ask
Use the tag "guava".
http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/jsr166y/ThreadLocalRandom.java?view=co
Martin
Whenever java.util.Random is a performance bottleneck,
one can consider using a non-synchronized version.
--
A thread local *should* be faster, but always test in as much of a
"real world" situation to be sure. Beware of micro-benchmarks. How
either approach behaves in practice will depend on many things,
including the number of cores, number of threads, contention, etc. The
basic reason is that the best way to improve throughput with multiple
threads is to remove any contention entirely (paraphrased from Brian
Goetz).
I should qualify that - that should be the case for a random number
generator which is, itself, fast. If you're random number generator is
not fast, pre-calculating them could certainly be an improvement.
- Ray
What kind of queue would you use to communicate the random numbers to the rest of the world? I'd worry that having lots of processors constantly bang on the queue would make this approach much less attractive than something like Martin's suggestion of ThreadLocalRandom.
On Wed, Jun 9, 2010 at 4:00 PM, Tim Peierls <t...@peierls.net> wrote:What kind of queue would you use to communicate the random numbers to the rest of the world? I'd worry that having lots of processors constantly bang on the queue would make this approach much less attractive than something like Martin's suggestion of ThreadLocalRandom.These days, Java has nice blocking queues, there is no banging.
Daemon processes are easy.
A BlockingQueue<T> is what you want.
These days, Java has nice blocking queues, there is no banging.By "constantly bang on" I mean "repeatedly take from".
Daemon processes are easy.Do you mean daemon threads?