“无法复制” - Java确定性多线程可能吗? [英] "Cannot reproduce" - is Java deterministic multithreading possible?

查看:106
本文介绍了“无法复制” - Java确定性多线程可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是否可以以确定的方式运行多线程Java应用程序?我的意思是在我的应用程序的两个不同运行中始终使用相同的线程切换。

Is this possible to run multithreaded Java application in a deterministic fashion? I mean to have always the same thread switching in two different runs of my application.

原因是在每次运行中以完全相同的条件运行模拟。

Reason for that is to run simulation in exactly the same conditions in every run.

类似的情况是当使用随机数生成器获得总是相同的随机序列时给出一些任意种子。

Similar case is when one gives some arbitrary seed when using random number generator to obtain always the same "random" sequence.

推荐答案

我不知道有任何实际的方法可以做到这一点。

I am not aware of any practical way to do this.

从理论上讲,它可以实现在某些假设 1 下具有完全确定性行为的字节码解释器。您需要通过完全在软件中并使用单个本机线程实现线程和线程调度来模拟多个线程。

In theory, it would be possible to implement a bytecode interpreter with an entirely deterministic behavior under certain assumptions1. You would need to simulate the multiple threads by implementing the threads and the thread scheduling entirely in software and using a single native thread.

1 - 例如,没有I / O,也没有使用系统时钟。

这篇关于“无法复制” - Java确定性多线程可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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