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"