Java遊戲服務器生成唯一長整型值:
package com.game.config;
import com.game.server.Server;
/**
*
* 服務器配置 @
*/
public class Config {
private static int id = 0;
private static Object obj = new Object();
/**
* 獲得唯一id
* @return id
*/
public static long getId(){
synchronized (obj) {
id = id + 1;
return (((long)(Server.server_id & 0xFFFF)) << 48) | (((System.currentTimeMillis() / 1000) & 0x00000000FFFFFFFFl) << 16) | (id & 0x0000FFFF);
}
}
}