The previous code may result in generating duplicate IDs. Here is the corrected
code:
| package org.jboss.ejb.txtimer;
|
| import java.math.BigInteger;
| import java.net.InetAddress;
|
| public class BigIntegerClusteredTimerIdGenerator implements
TimerIdGenerator {
| private static BigInteger nextTimerId = BigInteger.valueOf(0);
| private static String offset = "";
|
| static {
| try {
| byte[] ob = InetAddress.getLocalHost().getAddress();
| for (int i=0; i<ob.length; i++) {
| if (ob[ i ] < 10) {
| offset += "0";
| }
| offset += String.valueOf(ob[ i ]);
| }
| } catch (Exception e) {
| }
| }
|
| public synchronized String nextTimerId() {
| nextTimerId = nextTimerId.add(BigInteger.valueOf(1));
| return offset + nextTimerId.toString();
| }
| }
|
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3871013#3871013
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3871013
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
JBoss-Development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-development