【发布时间】:2016-03-16 19:50:52
【问题描述】:
所以我目前正在创建一个数据分析和预测程序,出于测试目的,我正在模拟大量数据(在 10,000 - 1,000,000 范围内)“试验”。数据是理论游戏的模拟比赛。每场比赛都有回合。该程序的基本伪代码是这样的:
main(){
data = create(100000);
saveToFile(data);
}
Data create(){
Data returnData = new Data(playTestMatch());
}
Match playTestMatch(){
List<Round> rounds = new List<Round>();
while(!GameFinished){
rounds.add(playTestRound());
}
Match returnMatch = new Match(rounds);
}
Round playTestRound(){
//Do round stuff
}
现在,我想知道是否可以在多个线程上处理这些回合的模拟以加快进程。我不熟悉多线程背后的理论,所以请有人帮我完成这个,或者向我解释为什么这不起作用(不会加快进程)。谢谢!
【问题讨论】:
-
你的代码是thread-safe吗?
-
参见 java.util.concurrent Executors 和 ExecutorService
-
使用Amdahl's Law 确定您的代码并行化多少可以加快速度。
标签: java multithreading statistics analytics simulation