为 Web 应用程序生成序列号

发布于 2024-12-03 00:53:27 字数 120 浏览 0 评论 0原文

要求:需要为每个网络请求生成一个唯一的编号,该编号用于唯一标识交易并跟踪交易传播,并且该编号将返回给客户端以供将来参考。这是一个java web应用程序,我想知道可用于执行此操作的方法..(无需连接数据库即可获取键值)提前致谢

The requirement : it is require to generate a unique, number for a each and every web request, this number is used to identify the transaction uniquely and track the transaction propagation and this number will return to client for future reference. this is a java web application i would like to know the methods available to do this..(without connenct db get a key value)Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百思不得你姐 2024-12-10 00:53:28

您是否尝试过使用 java UUID

这是有关如何生成它们的教程

Have you tried with the java UUID?

Here is a tutorial on how to generate them

雨巷深深 2024-12-10 00:53:27

如果您仅运行应用程序的单个实例,只需使用 AtomicLong.incrementAndGet()。但需要在关机前保留,否则重启后始终从0开始。

否则,必须使用 UUID 类,该类是普遍唯一的 128 位值。

If you are running only single instance of your application, simply use AtomicLong.incrementAndGet(). However it needs to be persisted prior to shutdown, otherwise it will always start from 0 after restart.

Otherwise UUID class has to be used which is universally unique 128-bit value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文