[英]Sorted Data Structure which is efficient and can store the original message with the respective timestamps
I want to send different XML message strings based on the time. 我想根据时间发送不同的XML消息字符串。 I have thought of implementing a data structure in JAVA and put all the XML messages in it with the time when they should be sent out. 我考虑过要在JAVA中实现数据结构,并在所有XML消息发送出去的时间里放入其中。 I want to use sorted data structure so that every time the message comes inside the data structure, it gets sorted and while sending out I can check their respective times and take the messages out. 我想使用排序的数据结构,以便每当消息进入数据结构中时,消息都会被排序,并且在发送时我可以检查它们各自的时间并取出消息。 I want to know which data structure would be most efficient and how can I implement it. 我想知道哪种数据结构将是最有效的,以及如何实现它。 Also how can I put time in seconds with each XML string. 另外,如何将每个XML字符串的时间以秒为单位。
It is like: 它像是:
Message 1, time to send T + 1 ---- put to the data structure
Message 2, time to send T + 4 ---- put to the data structure
Message 3, time to send T + 3 ---- put to the data structure....
There will be a separate thread that will check the messages in the data structure every second and remove all the messages which qualifies to come out. 将有一个单独的线程,它将每秒检查一次数据结构中的消息,并删除所有符合条件的消息。
If I understood your problem properly. 如果我正确理解您的问题。 You want 你要
If The above cases ae right then I think you will need a thread-safe queue. 如果上述情况正确,那么我认为您将需要一个线程安全队列。 Because 因为
In this case the ava.util.concurrent.ConcurrentLinkedQueue will be a good option 在这种情况下, ava.util.concurrent.ConcurrentLinkedQueue将是一个不错的选择
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.