Theoretically, I don't think this method will return repeated UUIDs, even from different devices.

Let's check the documentation of android: http://developer.android.com/reference/java/util/UUID.html. It says "Generates a variant 2, version 4 (randomly generated number) UUID as per RFC 4122."

Even in JDK documentation http://docs.oracle.com/javase/6/docs/api/java/util/UUID.html , it says they are implementing RFC 4122.

And in RFC 4122, http://www.ietf.org/rfc/rfc4122.txt, it says "A UUID is 128 bits long, and can guarantee uniqueness across space and time."

Wikipedia also calculates the probability of duplicates of RandomUUID: http://en.wikipedia.org/wiki/Universally_unique_identifier#Random_UUID_probability_of_duplicates

There is a guy here ( http://www.coderanch.com/t/385404/java/java/UUID-Uniqueness-JVMs) states that "We (i.e. my team at work) have been using the Java Util UUID class for UUIDs across JVMs."

However, I still can see a lot of worries that the Java randomUUID will not be unique.

First of all, let us check the wikipedia: http://en.wikipedia.org/wiki/Universally_unique_identifier. It says java is not using MAC address for generating UUID "due to lack of means to access MAC addresses using pure Java before version 6". It also gives opensource UUID generation tools as http://johannburkard.de/software/uuid/ and https://github.com/cowtowncoder/java-uuid-generator. Not sure not using MAC address will make them not unique.

Some people here ( http://www.coderanch.com/t/385404/java/java/UUID-Uniqueness-JVMs) also say they are using a central control to generate UUID.

This link( http://stackoverflow.com/questions/2513573/how-good-is-javas-uuid-randomuuid ) says "implementation to contain subtle bugs that ruin all this (see OpenSSH key generation bug)".

This link( http://stackoverflow.com/questions/6505837/is-oracles-sys-guid-uuid-rfc-4122-compliant) says "SYS_GUID is Oracle's equivalent of UUID. It is globally unique. However, it is not compliant to RFC 4122".

Anyway, I do not find any evidence that says UUID.randomUUID() will repeat, even from different machines.
As it says here (http://stackoverflow.com/questions/2513573/how-good-is-javas-uuid-randomuuid), "I don't think there's any concrete reason to worry about Java UUIDs's randomness."

However, if we are building very critical distributed applications with a lot of data, maybe, we can consider using MAC address algorithm, or using central UUID generator.

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)设计的几处硬伤
  2. Develop one game for playing
  3. [置顶] Android如何选择HttpURLConnectio
  4. Android(安卓)RecyclerView DividerItemD
  5. Android™ 2.1系统图标
  6. android:maxLines与android:ellipsize冲
  7. Android自定义权限
  8. android收货地址整理
  9. Android(安卓)TextView 如何判断是否已经
  10. Android(安卓)UI线程和非UI线程