⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uidgenerator.java

📁 这个是网络上下载的一个struct框架的程序
💻 JAVA
字号:
/*** * jwma Java WebMail * Copyright (c) 2000-2003 jwma team * * jwma is free software; you can distribute and use this source * under the terms of the BSD-style license received along with * the distribution. ***/package com.struts2.framework.util;import java.rmi.server.UID;import java.net.URL;import java.io.DataInputStream;import java.util.Random;/** * Utility class exposing a method that will return * a unique identifier. * * @author Dieter Wimberger * @version 0.9.7 07/02/2003 */public class UIDGenerator {  //class attributes  private static Random m_Random;  private static int m_ReseedCounter = 0;  //create seeded random  static {    m_Random = new Random();    seedRandom();  }  /**   * Returns a UID (unique identifier) as <tt>String</tt>.   * The identifier represents the MD5 hashed combination   * of a <tt>java.rmi.server.UID</tt> instance, a random padding of   * <tt>RANDOM_PADDING</tt> length, it's identity hashcode and   * <tt>System.currentTimeMillis()</tt>.   *   * @return the UID as <tt>String</tt>.   */  public static final synchronized String getUID() {    byte[] buffer = new byte[RANDOM_PADDING];    String u = new UID().toString();    int i = System.identityHashCode(u);    long d = System.currentTimeMillis();    //create random padding    m_Random.nextBytes(buffer);    u = u + new String(buffer);    if (m_ReseedCounter == RANDOM_RESEED) {      seedRandom();      m_ReseedCounter = 0;    } else {      m_ReseedCounter++;    }    return MD5.hash(u + i + d);  }//getUID  /**   * If the <tt>HotBits</tt> Server is available, <tt>Random</tt>   * will be seeded with a real random long.   * <p>   * <a href="http://www.fourmilab.ch/hotbits/">HotBits</a> is located   * at Fermilab, Switzerland.   *   */  public static final void seedRandom() {    try {      URL url = new URL(HOTBITS_URL);      DataInputStream din = new DataInputStream(url.openStream());      m_Random.setSeed(din.readLong());      din.close();    } catch (Exception ex) {      //use what is available      m_Random.setSeed(System.currentTimeMillis());    }  }//seedRandom  public static final void main(String[] args) {    int i = 0;    long start = System.currentTimeMillis();    while (i < 1000) {      System.out.println(getUID());      i++;    }    long stop = System.currentTimeMillis();    System.out.println("Time =" + (stop - start) + "[ms]");  }//main  public static final int RANDOM_PADDING = 256;  public static final int RANDOM_SEED_LENGTH = 6;  public static final int RANDOM_RESEED = 1000;  public static final String HOTBITS_URL =      "http://www.fourmilab.ch/cgi-bin/uncgi/Hotbits?nbytes=" +      RANDOM_SEED_LENGTH +      "&fmt=bin";}//UIDGenerator

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -