Java generates a 32-bit UUID Universal Unique identifier (universally unique Identifier)

Source: Internet
Author: User
Tags uuid

Why use a UUID instead of a growth model?

First, why use a UUID to control the primary key?

What is the advantage of comparing the primary key of an automatically growing int type.

When the amount of data is much, the number of logged-in users, encountered high concurrency, the growth is not conducive to maintenance, but also not conducive to expansion, and there may be several people at the same time inserted from the growth of the same ID such as from the growth of 100,ABC three users at the same time will not appear at the same time Insert 101. or cover 101 of data. That's the downside.

However, a UUID-controlled Word automatically generates an identification number when the invocation is inserted ...

generate a 32-bit UUID string

<span style= "FONT-SIZE:14PX;" >package Com.cmcc.tools;

Import Java.util.UUID;

public class Uuidtool {public

	Uuidtool () {
	}
	/**
	 * automatically generates a 32-bit UUID, which is used to insert the primary key ID of the corresponding database.
	 * @return */public
	static String Getuuid () {
		/*uuid UUID = Uuid.randomuuid ();
		String str = uuid.tostring ();
		Remove the "-" symbol
		String temp = str.substring (0, 8) + str.substring (9)
				+ str.substring (+) + str.substring (19, )
				+ str.substring (in);
		Return temp;*/return
		
		uuid.randomuuid (). toString (). Replace ("-", "");
	}


	public static void Main (string[] args) {
//		string[] ss = Getuuid;
		for (int i = 0; i < i++) {
			System.out.println ("ss[" + i + "]=====" + getuuid ());
}}} </span>



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.