Java UUID generation tool concurrency Test

Source: Internet
Author: User

Java UUID generation tool concurrency TestI. Know UUID
Wikipedia, a free encyclopedia

The universal Unique Identifier (UUID) is a standard for Software construction. It is also the organization of the Open Software Foundation (OSF) in the Distributed Computing Environment (Distributed Computing Environment, DCE) a part of the field.

The purpose of UUID is to allow all elements in the distributed system to have unique identification information without specifying the identification information through the central control terminal. In this way, each user can create a UUID that does not conflict with others. In this case, duplicate names are not required during database creation. At present, the most widely used UUID is Microsoft's Globally Unique Identifiers (GUIDs, linux ext2/ext3 file system, LUKS encrypted partition, GNOME, KDE, Mac OS X, and so on. In addition, we can find the implementation in the UUID library in the e2fsprogs package.

[Edit] Definition
A UUID is composed of a 16-byte 16-byte or 128-bit hexadecimal number. Therefore, the total number of UUID is 216x8 = 2128 in theory, it is about 3.4x1038. That is to say, if 1 mb uuid is generated every second, it takes 10 billion years to use up all UUID.

The standard UUID contains 32 16-digit numbers, which are separated into five segments in the form of 8-4-4-12 32 characters. Example;

550e8400-e29b-41d4-a716-446655440000
UUID can also be repeated to indicate the same type. For example, in Microsoft COM, all components must implement the IUnknown interface by generating a UUID representing the IUnknown. Whether the program attempts to access the IUnknown interface in the component or the component that implements the IUnknown interface, as long as the IUnknown is used, it will be referred to the same ID: comman0000-0000-0000-c000-000000000046.

[Edit] Random UUID repetition rate
For example, the random UUID generated by java. util. of the 128 bits generated by the UUID class), 122 bits are Randomly generated, and 4 bits are used in this version 'randomly generated uuuid, two more are used in its variant 'leaching-salz. Using the birthday paradox, we can calculate that the probability of two UUID with the same value is about


The following is the probability of collision after n UUID is calculated based on x = 2122:

N Probability
68,719,476,736 = 236 0.0000000000000004 (4x10-16)
2,199,023,255,552 = 241 0.0000000000004 (4x10-13)
70,368,744,177,664 = 246 0.0000000004 (4x10-10)

Compared with the probability of a person being hit by a meteorite, it is known that the probability of a person being hit by a meteorite is estimated to be 1 [1] In 17 billion, that is, the probability is about 0.00000000006 (6x10-11 ), it is equivalent to setting up tens of megabytes of UUID in one year and repeating it once. In other words, 1 billion UUID is generated every second, and the probability of only one repetition after 100 is 50%. If every user on the Earth has 0.6 billion UUID, the probability of a repetition is 50%.

Duplicate UUID generation and errors are very low, so you do not have to consider this issue.

The probability is also related to the quality of the random generator. To avoid increasing the chance of repetition, you must use a pseudo-random number generator based on cryptography to generate values.
Http://zh.wikipedia.org/zh-cn/UUID 2, Java 5 UUID after Java 5, UUID generated into a single disc of small, directly generated. There are four basic UUID types: time-based UUID, DCE Security UUID, name-based UUID, and randomly generated UUID. These types of version values are 1, 2, 3, and 4, respectively. For more information, see the JDK documentation. Here, we mainly want to generate UUID through multiple threads to test whether the UUID will be repeated and how efficient it is: import java. util. UUID;
Import java. util. concurrent. ExecutorService;
Import java. util. concurrent. Executors;

/**
* Java UUID generation tool concurrency Test
*
* @ Author leizhimin 2010-7-10 16:25:13
*/
Public class TestUUID implements Runnable {
Public static void main (String [] args ){
ExecutorService pool = Executors. newFixedThreadPool (5 );
For (int I = 0; I <8; I ++ ){
Pool.exe cute (new TestUUID ());
}
Pool. shutdown ();
}

Public static String genReqID (){
// Return UUID. randomUUID (). toString (). replace ("-", ""). toUpperCase ();
Return UUID. randomUUID (). toString (). toUpperCase ();
}

Public void run (){
For (int I = 0; I <10; I ++ ){
System. out. println (genReqID ());
}
}
} 20F644DE-23C5-4E04-BE38-991710D2DA13
93349C44-D8BA-495E-A687-44AE3FAEA9A5
BEB86A25-A9E5-47DC-BC22-157E021EAD3C
C990218F-C925-4A41-8006-D4489145CED6
767CD9B4-4E6A-4D53-BE96-CF35E6F69D60
A3876D8D-E807-492E-9054-28B9289EB5C5
17DD2BCD-E710-4F7A-B8F3-6BB19201E15B
901CCE61-4E47-4B2B-AA06-22A023D78313
81473B2F-FBC1-4D3D-834E-DEFFBD3C510C
46980DBD-E6A0-46E6-8FE9-E2E5766C2442
0BF83A5F-7A31-44C2-AE7F-EB4281F9CDE0
E35383D0-4850-45A1-B764-F8760BF1707B
772A2E21-ABAF-47AE-978C-AF70F40313F1
0DB815CF-C7B5-4E2F-B2DB-E84BC7B616F8
C826D9B7-E1F3-4F8E-8AAF-A61197AAFCCF
26CF2391-7C01-43FE-B515-5BD5DA6AF0B3
2544da-e-d9c3-4d4d-b2cb-2a771_d4167
5BED5394-59DA-4E45-8182-34A24E1D2AC2
F32F5F1E-6C6F-4C9F-9944-6CE4EC8768F7
775F0B36-0965-4BA8-B1AA-FD1CFBE2B718
32DA0548-B562-444D-A16A-7E535EAA3C93
C935101E-7365-45C5-BBD1-3A64F2EC33C2
E623EC45-1F7E-4973-8132-424C134C7096
86AFEE47-AFD7-4479-B30D-0C2632087404
847F46FA-D112-4CB7-86E4-640F03A1E676
FA45ADA6-6A63-4961-B7C5-9501B21E116A
3E21CBC8-C116-437A-BAEC-4AD02F711F02
6025c077-440d-4458-bbeb-66d47fcf2206
09f7872d-90ee-00001-9463-1609200ce615
5FB07DF6-BA89-4017-BE9D-592DB6EADF05
6d7627ad-rjc-4e69-b0a7-3674ccbdee79
1E4E5E7D-AE3F-419F-836E-F284842261A6
1FFD670E-EC2C-462A-8E82-DACC21CF153A
FB5868EE-5330-4F6D-8CEE-0B1A50156E26
A38918F7-FB35-4560-9810-BE0B649E8D20
009508E8-0C9B-4189-BB5F-159F7EB2AAB6
30132165-0207-40B0-943F-E34B401D724F
CA5D15A0-490B-47D7-BF2A-9D58F8742E5B
BCE31255-156D-479E-B4EC-949A731B3FF2
A6CC370E-AFE0-439A-AFF3-37A76687B259
27894607-1CEF-43C2-93FC-75B59CB617A9
39ABD92B-D4CE-4B3C-BB70-D94739849DA2
04d2e913-75c2-1166-8ed7-5a95f023dcfd
FE853E35-72C6-422C-A7C4-CC4C0A4C9A98
7A6D6722-BC13-4965-95D4-F35B428E297D
92A4831A-A60E-4C16-AD8F-C8AC839436FF
9B58249F-3F6F-4434-ACF6-00F51A971243
7DDB1ABC-7918-4465-B8E3-0CB59D63F979
EF43F137-63D1-4361-BFB6-4A5C51B86C12
B785B7FE-FBA4-49B1-ADF8-CFD6107D9DB6
68EA68F7-A56B-4DDA-A832-BCD59BF67BA1
09F7E3E5-4344-49F7-992B-0E0B33D11296
78EEBA04-C836-44ED-829F-6F55E3E758A4
A4333A46-482B-47BE-87D0-BC0666EAE8FC
38E1212E-3D11-4275-A50C-42D98CEF91C5
FD9EDACF-6345-435E-B8A2-D8CDA8A66EE0
24925FA8-BB81-4639-BFFA-A12CA99E419F
B6994147-4AC2-414C-9669-9DC3E4BE8F88
1938E265-B213-46AC-A349-678B7E029771
485757B6-7C6E-4CFF-959B-6DF94DC282B6
C43E385D-B798-4FE0-8F50-2DCC8370655E
1910000a29-e2c9-4daf-a5ee-481_d719d66
8773F8F0-45C5-463B-85EB-97E8395CBB81
2B5F6CB2-E1F2-44A8-A60E-C8CD4191EE52
65775AF5-34C6-491A-8DED-A257E2480C62
A6F23801-B2E2-40A4-9415-43797BF14DD8
D1E386E3-6BBF-40E0-BF84-E0C41F32B6E7
97a836a3-64f9-4f417ad78-238cf1b8f413
32CE9D3D-EDA1-4E8C-87B9-DBAAD389FBAA
F2467331-CC34-49C1-9A3B-7566AE525B3B
847C08A3-D8AE-4C66-84F7-28387AD84EA9
5e8a99e6-600e-4797-b590-72345425e295
6B576614-4F9D-4018-98A8-ECCFDEA045B0
27070E60-ACE5-474D-AA47-8A4F37D16742
18BB8499-7836-4ACC-A301-167D52AB3D3F
8EC342B2-555A-4EAC-A82D-5AC6C7941421
5BF92378-7EFD-4454-806C-DFBFE51753C3
1a5b0717-07c0-46ea-8f3d-6246425d9fb1
C3C642CE-A05E-496D-85E6-4830CF39970B
74B751BF-5CA5-4526-AFB8-2AA467852976

Process finished with exit code 0 the UUID is in lower case. I changed it to upper case. It can be found that the UUID is of the same length and has 36 characters. If the connection line is removed, the UUID is exactly 32 characters. In fact, you can remove the connection line because the connection line is in the same position. The removal method is simple: return UUID. randomUUID (). toString (). replace ("-",""). toUpperCase (); Through the above test, the UUID generation speed is still very fast under multiple threads.

This article is from the "melyan" blog, please be sure to keep this source http://lavasoft.blog.51cto.com/62575/347354

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.