hadoop-common-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shashwat shriparv <dwivedishash...@gmail.com>
Subject Re: Reg:Sequence id generation
Date Thu, 07 Jun 2012 13:22:04 GMT
Try something like this :


public class MyUniqueNumber
{
    private static MyUniqueNumber myUniqueNumber;
    int number;
    int seedValue=365432; //custom seed value to begin with

    private MyUniqueNumber(){ //Singleton !!!
        number=seedValue; //init to zero
    }

    public static MyUniqueNumber getInstance(){
        if(myUniqueNumber==null){
            myUniqueNumber=new MyUniqueNumber();
        }
        return myUniqueNumber;
    }

    public int getUniqueNumber(){
        number+=1; //simple increment by 1 , you can modify this further
        return number;
    }
    public static void main(String[] args)
    {
        MyUniqueNumber myUniqueNumber=MyUniqueNumber.getInstance();
        for(int n=0;n<=5;n++){
            System.out.println("read number:
"+myUniqueNumber.getUniqueNumber());
        }
    }
}


On Thu, Jun 7, 2012 at 6:14 PM, abhishek dodda <abhishek.dodda1@gmail.com>wrote:

> hi all,
>
>       I have a scenario where i should generate the sequence id . All
> my tables are in DB2
>



-- 


∞
Shashwat Shriparv

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message