Java中是否有适合用作“模拟时钟”的类?在离散事件模拟中?
本质上,我正在寻找一种模拟时钟的东西,并且可以通过调用一种方法向前递增一个时间单位。在标准 Java 库中可以找到类似的东西吗?或者你必须自己实现这个?
Essentially I'm looking for something that models a clock and can be incremented forward by one unit of time by invoking a method. Anything such as this to be found in the standard Java library? Or would you have to implement this yourself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
一个简单的整数怎么样? - 它可以加一:
counter++
或者
java.util.concurent.atomic.AtomicInteger
(如果您有多个线程)。它甚至提供了incrementAndGet()函数。What about a simple integer? - It can be incremented by one:
counter++
Or the
java.util.concurent.atomic.AtomicInteger
if you have several threads. It even provieds aincrementAndGet()
function.看看 SimKit。它是一个基于java的开源离散事件引擎。它有详细记录,您可以提取时钟和事件列表并根据您自己的目的进行自定义。它得到了很好的支持,因为它被用来向研究生教授 DES 入门课程。
http://diana.nps.edu/Simkit/
Take a look at SimKit. It's a java based open source discrete event engine. It's well documented and you can extract the clock and the event list and customize for your own purposes. It's well supported since it's used to teach an introductory course to DES to grad students.
http://diana.nps.edu/Simkit/
标准的 Calendar / GregorianCalendar 应该可以满足您的要求。
A standard Calendar / GregorianCalendar should do the trick for you.
根据您的用例,请查看以下内容:
简单:
可变 (org.apache.commons.lang.mutable.*):
线程安全:
Depending on your use case, look into the following:
Simple:
Mutable (org.apache.commons.lang.mutable.*):
Threadsafe:
我不了解标准的 Java API,但在推出自己的 API 之前请先查看 Quartz
I don't know about the standard Java API, but check out Quartz before rolling your own