开发者

Efficient Java observer design for distributing sensor data (~40Hz)

开发者 https://www.devze.com 2023-01-21 22:02 出处:网络
Hi:I want to design a structure for letting sensor data ( 3 float values at around ~40Hz) be accessible through something like an Observable. But by using the java Observable/Observer class a high ove

Hi:I want to design a structure for letting sensor data ( 3 float values at around ~40Hz) be accessible through something like an Observable. But by using the java Observable/Observer class a high overhead will affect the performance. What are the known approache开发者_StackOverflow社区s to keep it efficient and make it structured as well?


The 'overhead' of using an Observable interface is very small, and even at 40Hz is probably not going to impact performance. I strongly recommend trying it to see what the performance is like.

One issue is that the java.util.Observable class simply tells the observer that a change has taken place, forcing the Observer to go and get the data. This might be considered a performance degradation if getting the information about of the Observable takes time. You might want to implement your own variant on Observable in which the new data is passed to each Observer as an argument to the notification call.

0

精彩评论

暂无评论...
验证码 换一张
取 消