가끔 코딩을 하다가 보면 unique한 값을 사용해야 할때가 있다.

여러가지 조합으로 만들기도 하지만, 자바 자체의 API를 이용해서 좀더 편하게 만들수 있을 것이다.

A UID represents an identifier that is unique over time with respect to the host it is generated on, or one of 216 "well-known" identifiers.

  • unique, an int that uniquely identifies the VM that this UID was generated in, with respect to its host and at the time represented by the time value (an example implementation of the unique value would be a process identifier), or zero for a well-known UID
  • time, a long equal to a time (as returned by System.currentTimeMillis()) at which the VM that this UID was generated in was alive, or zero for a well-known UID
  • count, a short to distinguish UIDs generated in the same VM with the same time value

    http://java.sun.com/j2se/1.5.0/docs/api/java/rmi/server/UID.html


    VMID is a identifier that is unique across all Java virtual machines. VMIDs are used by the distributed garbage collector to identify client VMs.

    VMID()
    Create a new VMID. Each new VMID returned from this constructor is unique for all Java virtual machines under the following conditions: a) the conditions for uniqueness for objects of the class java.rmi.server.UID are satisfied, and b) an address can be obtained for this host that is unique and constant for the lifetime of this object.


    http://java.sun.com/j2se/1.5.0/docs/api/java/rmi/dgc/VMID.html

    분산환경에서 여러개의 VM이 존재를 한다면, UID보다는 VMID를 추천하고 싶다.


    샘플 코드르 작성해봤다.

    User inserted image


    이건 실행결과다. 원하는 필드의 사이즈에 맞게 적절하게 사용하면 되겠다.

    User inserted image

  • 트랙백 보낼 주소 :: http://www.ologist.co.kr/trackback/485

    댓글을 달아주세요:: 네티켓은 기본, 스팸은 사절

    1. 2008/05/23 04:22
      댓글 주소 수정/삭제 댓글
      중대하고 유용한 위치!
    2. 2008/05/23 04:52
      댓글 주소 수정/삭제 댓글
      일! 우수한 감사!
    3. 2008/05/23 05:25
      댓글 주소 수정/삭제 댓글
      그런 위치를 경이롭 위해 많게의 감사!
    4. 2008/05/23 05:55
      댓글 주소 수정/삭제 댓글
      저에서 유사한 역사는 이었다.
    5. 2008/05/24 00:14
      댓글 주소 수정/삭제 댓글
      걸출한 디자인! 좋은 디자인.
    6. 2008/05/24 01:49
      댓글 주소 수정/삭제 댓글
      정말 같지 않는 블로그!
    7. 2008/05/24 02:05
      댓글 주소 수정/삭제 댓글
      아주 좋은 나는 위치 그것을 감사 좋아한다!


    BLOG main image
    OOP and Java by ologist

    공지사항

    카테고리

    All (649)
    private!! (106)
    WEB & IT (140)
    Developer (400)