java.util.UUID存在并发问题吗
PHP中文网
PHP中文网 2017-04-18 09:26:25
0
2
411

如题所述,有根据最好了,或者说在highly mutilthread env环境下,加synchronized wrapper下吗,怎么才能比较好的降低并发产生,又不大范围(如果使用这个生成随机串的次数很多,比如一天百万级别的,对于生成随机串怎么降低或者说保证唯一)影响性能.

http://stackoverflow.com/questions/7212635/is-java-util-uuid-thread-safe
http://bugs.java.com/view_bug.do?bug_id=6611830

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
Peter_Zhu
  1. This BUG链接里面也说了在JDK1.7里面已经被Fix掉了.所以UUID目前看来在JDK1.7 and above versions have no concurrency issues

  2. In fact, UUID is a very performance-intensive way to obtain a unique key. In a distributed environment, it is recommended to directly use the local IP and the auto-incremented AtomicLong (of course you can add a random number) to complete the uniqueness of the entire distribution Key generation

迷茫

Thanks for the invitation.
For example, the generation of order numbers in e-commerce generally involves pre-generating order numbers for a certain day (estimated quantity, for example, there were 1 million orders yesterday, and 1 million + certain redundancy will be generated today), and placed on caches such as memcache or redis, and It can be placed in MQ as an order number pool. If you want to use it, just consume the one in the order number pool, which is absolutely unique.
How to generate achievements depends on your business logic. Generally, if you want to have no duplication at all, you can generate a sequence of 0~100W and then shuffle it.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!