我是靠谱客的博主 复杂向日葵,最近开发中收集的这篇文章主要介绍java三个窗口轮流售票,java多个线程轮流,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I have 2 java threads receiving UDP multicast.

Each thread will receive UDP packets from different multicast streams of say around 60 Mbps, then processes UDP packets and queues in shared BlockingQueue. UDP packets are of around 1300 bytes.

I want order of processed UDP packets in queue, which is same as how packets reached to NIC of machine, even if receiving packets from different threads(different multicast streams).

I am not able to achieve this in these threads, that is my problem.

Is it possible using java, or should I use some other language like C?

EDIT

Basically, threads will receive multicast from different multicast streams, and packet order in queue will depend on order how receiving threads executed to take packets from NIC, but I want order to be same as how packets reached to NIC.

I tried lowering UDP receive buffer for each stream, packets were getting in queue almost in order but packets started losing. If I increase receive buffer, order in queue completely depends on how receiving threads executed.

Please help me on this. Is it possible?

解决方案

Sequence numbers? Define a stream-control class that contains a sequence-number that is incremented and loaded into each buffer object received from that stream, a 'last-processed' number that the pool threads can check and a list for every out-of order buffer that is dequeued by your pool.

The pool threads check to see if the buffer they dequeue has the correct sequence-number, (last-processed+1). If so, they process that buffer and any subsequent numbers in the listed buffers. If not, they add that buffer to the list for later processing.

PS: The stream-control class methods will need locking up, for sure.

最后

以上就是复杂向日葵为你收集整理的java三个窗口轮流售票,java多个线程轮流的全部内容,希望文章能够帮你解决java三个窗口轮流售票,java多个线程轮流所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(71)

评论列表共有 0 条评论

立即
投稿
返回
顶部