Java Learning---Generating an in-memory duplicate ID

Source: Internet
Author: User

Idutils.java

Import java.util.random;/** * Various ID generation strategies * <p>Title:IDUtils</p> * <p>description: </p> * @version 1 .0 */public class Idutils {/** * picture name generated */public static String Genimagename () {//Fetch the current time long shaping value contains milliseconds long Millis = system.current Timemillis ();//long Millis = System.nanotime ();//plus three-bit random number randomly random = new random (), int end3 = Random.nextint (999);// If less than three bits in front of 0String str = Millis + String.Format ("%03d", End3); return str;} /** * Product ID generation */public static long Genitemid () {//Take the long shape value of the current time contains milliseconds long Millis = System.currenttimemillis ();//long Millis = Sy Stem.nanotime ();//plus two-bit random number randomly random = new random (), int end2 = Random.nextint (99),//if less than two bits in front of 0String str = Millis + stri Ng.format ("%02d", end2); Long id = new Long (str); return ID;} public static void Main (string[] args) {for (int i=0;i< 100;i++) System.out.println (Genitemid ());}}

Java Learning---Generating an in-memory duplicate ID

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.