Java int用完了20亿,怎么办 [英] Java int is run out of 2 billions, how to do

查看:631
本文介绍了Java int用完了20亿,怎么办的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java应用程序中使用int作为PK,现在它已经达到了最大int值(2十亿),即使在DB它可以存储的数量比它。但是java int只能容纳大约2亿。

I used int as PK in Java application, now it has reached the max int value (2 billions), even in DB it can store the number more than it. but java int is only able to hold around 2 billions.

我无法将int更改为long以与DB对齐。

I am unable to change int to long to align to DB. because it's huge effort.

推荐答案

Java中的Integer的最大值为2,147,483,647。如果你需要一个更大的数字,你必须改变为一个长。你也可以使用整数的负值范围,但如果你已经达到最大值,很可能是你很快就会用完了。

The maximum value for an Integer in Java is 2,147,483,647. If you need a bigger number, you'll have to change to a long. You could also use the negative range of the Integer, but if you've already hit the maximum, the likelihood is that you'll run out of room pretty soon.

但是,如果DB中没有20亿个元素,则可以重用未使用的主键。这可能是低效的,因为你必须搜索未使用的密钥。

However, if you don't have 2 billion elements in the DB, you could reuse the unused primary keys. This would probably be inefficient, because you'd have to search for unused keys.

我建议你只是经历改变代码的努力。长远来说,现在付出的努力将会得到回报。

I'd suggest just going through the effort of changing the code. Putting in the effort now will pay off in the long run.

这篇关于Java int用完了20亿,怎么办的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆