简体   繁体   English

在Java仿真中测量统计

[英]measuring statistics in java simulation

I have a group of nodes who send measurements to a bootstrap server. 我有一组将测量值发送到引导服务器的节点。 In the end I want the bootstrap server to sum all the measurements and write it to a file. 最后,我希望引导服务器将所有测量值求和,然后将其写入文件。 One way to do that is to over-write the data to the file each time a measurement message is received(after summing up the current measurements). 一种方法是在每次接收到测量消息时(将当前测量值求和后)将数据覆盖到文件中。 But this would be very inefficient. 但这将是非常低效的。 I want to store the measurement data and write it to file only once after the simulation is completed. 我想存储测量数据,并在模拟完成后仅将其写入文件一次。

But the problem is that the simulator code that I am using is not under my control, its a library that I am using. 但是问题是我正在使用的模拟器代码不受我的控制,而是我正在使用的库。 So, I cant tell when exactly the simulation is going to end (and hence I cant tell which measurement message will be the last one). 因此,我无法确定仿真何时确切结束(因此,我无法确定哪个测量消息将是最后一条)。

I naively tried to store the measurement data in a static class but this data is not accessible when the simulation terminates. 我天真地尝试将测量数据存储在静态类中,但是在模拟终止时无法访问此数据。 Is there any other way that I can do this ? 我还有其他方法可以做到这一点吗?

Thanks, 谢谢,

I would find the last message using a timeout. 我会使用超时找到最后一条消息。

Write to disk if you have new data but you haven't got anything for a while eg a second. 如果您有新数据,但是一段时间没有任何数据,则写入磁盘。

If you cannot store the data you need in the process (which it seems you can't, since the static class failed), you need to persist the data some other way. 如果无法存储过程中所需的数据(由于静态类失败,似乎无法存储),则需要以其他方式持久化数据。 To an on-disk file is one option, and another common one would be to a database. 磁盘文件是一种选择,另一种常见选择是数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM