1.UUID Introduction
UUID meaning is a universal unique identifier (universally unique Identifier), which is a software construction standard and is also open Software Foundation, OSF
Organizations are used in a distributed computing environment (distributed Computing Environment, DCE) as part of the domain.
The purpose of the UUID is to allow all elements in a distributed system to have unique identification information without the need to specify the information through the central control terminal. In this way, everyone can create a UUID that does not clash with others.
In such a case, there is no need to consider the name duplication problem when the database is established. Currently the most widely used UUID is Microsoft's globally Unique Identifiers (GUIDs), while other important applications,
Linux ext2/ext3 file system, LUKS encryption partition, GNOME, KDE, Mac OS X, etc.
2.UUID Composition
The UUID guarantees that all machines in the same time and space are unique. Typically, the platform provides the generated APIs. Based on standard calculations developed by the Open Software Foundation (OSF), Ethernet card addresses, nanosecond-seconds, chip ID codes, and many possible numbers are used
The UUID is composed of the following parts:
(1) The current date and time, the first part of the UUID is related to the time, if you generate a UUID after a few seconds to generate a UUID, then the first part is different, the rest is the same.
(2) clock sequence.
(3) Globally unique IEEE machine identification number, if there is a network card, from the network card MAC address obtained, no network card is obtained in other ways.
The only drawback to the UUID is that the resulting string will be longer. The most common use of UUID for this standard is the GUID of Microsoft (Globals Unique Identifiers). In ColdFusion, the UUID can be easily generated with the Createuuid () function,
The format is: xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx (8-4-4-16), where each x is a hexadecimal number in the range of 0-9 or a-f. The standard UUID format is: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12);
3. Project Combat
UUID as the database data table primary key is a good choice to ensure that each generated UUID is unique.
A. Generating UUID
Need to use Java to bring the JDk;
Import Java.util.UUID; Public Static void Main (string[] args) {for (int i=0;i<10;i++= Uuid.randomuuid (). ToString () . ReplaceAll ("-", "" "); SYSTEM.OUT.PRINTLN (UUID);}}
B. Generating a specified number of UUID
/*** Get a specified number of UUID *@paramnumber int need to get UUID count *@returnstring[] UUID array*/ Public StaticString[] Getuuid (intNumber ) { if(Number < 1){ return NULL; } String[] Retarray=NewString[number]; for(inti=0;i<number;i++) {Retarray[i]=getuuid ();} returnRetarray;}/*** Get a UUID *@returnString UUID*/ Public Staticstring Getuuid () {string UUID=Uuid.randomuuid (). toString ();//Remove the "-" symbolreturnUuid.replaceall ("-", "" ");}
Java Generation UUID