关于java 生成流水号 现在有这样一个要求,生成注水,最大为999999,6位的长度,开始时,是000001,以后逐个递增。一天内保证唯一,如果大于最大值,则新开一个流水。要求在高并发下,操作,获取, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在数据库建个序列:-- Create sequence create sequence SEQ_TESTminvalue 1maxvalue 999999999999999999999999999start with 1increment by 1cache 20;取流水号用这个SQL即可:select TO_CHAR(MOD(SEQ_TEST.Nextval,1000000), '000000') CurrNo from dual; 并发情形下注意同步就OK了,如下public class NumberIncrementor { private static int counter = 1; public static void main(String[] args) { long sec = 0; while (sec++<9999999) System.out.println(getSequence()); } synchronized public static String getSequence(){ if (++counter>999999) counter=1; return String.format("%06d", counter); }} 有点小问题private static int counter = 0; 再提供给你一个高效的sql语句select lpad(SEQ_TEST.nextval,6,'0') from dual synchronized public static String getSequence(){ if (++counter>999999) counter=1;} 这样可行 关于Hibernate返回数据绑定对象的问题 DIV加样式 急求:javamail属性问题 加急。。。tomcat6.0配置oracle9.2.0.8 连接池问题。 请教servlet 转向jsp 为何getAttribute()获值而getParameter()为null呢? spring + struts多模块 找不到页面 JSP页面的问题 Middlegen-Hibernate的问题。 jb9里启动weblogic8.1的奇怪问题 成为党员对以后找工作有用吗 Spring web.xml中遇到了一个诡异问题 跪求java快排代码,要带注释的
-- Create sequence
create sequence SEQ_TEST
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;
取流水号用这个SQL即可:
select TO_CHAR(MOD(SEQ_TEST.Nextval,1000000), '000000') CurrNo from dual;
private static int counter = 1; public static void main(String[] args) {
long sec = 0;
while (sec++<9999999)
System.out.println(getSequence());
} synchronized public static String getSequence(){
if (++counter>999999) counter=1;
return String.format("%06d", counter);
}
}
private static int counter = 0;
synchronized public static String getSequence(){
if (++counter>999999) counter=1;
}
这样可行