What is Id

Source: Internet
Author: User

Recently, I took a function point from someone else. The table Id (long) is composed of the millisecond value of the current time and the playerId for String concatenation, playerId is the Id (long) of another Entity ).
There has been no problem in the test phase, but there is a problem after the release.
Java code
String newId = String. valueOf (playerId) + String. valueOf (System. currentTimeMillis ());
 
After the long value of the date + playerId, the storage type is string.
In the string value above, NumberFormatException occurs in Long. parseLong (value.
 
Now, let's see why.
The value range of long is (-9223372036854774808 ~ 9223372036854774807), occupies 8 bytes (63 to the power of-2 to 63 to 1 of 2 ).
The current time in milliseconds: 1316223521431;
The result is self-evident once the playerId reaches 7 digits !!!
 
Java code
Exception in thread "main" java. lang. NumberFormatException: For input string: "25430051316162482222"
At java. lang. NumberFormatException. forInputString (NumberFormatException. java: 48)
At java. lang. Long. parseLong (Long. java: 422)
At java. lang. Long. parseLong (Long. java: 468)
At org. test. core. AppMain. main (AppMain. java: 88)

Author: "song020cn"
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.