p****i 发帖数: 6135 | 1 背景其实是传统的producer, consumer case:
producers 会产生三种不同priority 的events,
consumers 必须1. 总是优先处理高priority的event, 2.同priority的events按先来
后到处理。
刚开始的设想是用priorityblockingqueue, 方便快捷
第一个concern是: priorityblockingqueue无法保证同priority的events能按先来后
到处理。
这个可以通过rewrite comparator解决
第二个concern比较大: priorityblockingqueue是用heap实现的, enqueue and
dequeue都是 log(n) 的操作,
对于我们的大数据量大约是不妥的
现在的想法是只好化简为繁作三个seperate FIFO queues, 分别对应high, medium,
low priority。
好处是dequeue, enqueue都是 O(1)了
坏处是似乎producers, comsumer之间的signalling只好我自己来做了?
除了wait, notify什么的, 还有别的选择吗?
有什么需要注意的吗? |
g*****g 发帖数: 34805 | 2 这不难呀,你需要的是实现一个自己的BlockingQueue,里面放三个
LinkedBlockingQueue,按三个优先级,把那些方法wrap一遍。接下来你需要的是一个
Threadpool。ThreadPoolExecutor拿过来直接用对你就够了。一个小时的活。
什么wait/notify统统用不到。没事把java.util.concurrent看一看,里面很多好东西。
【在 p****i 的大作中提到】 : 背景其实是传统的producer, consumer case: : producers 会产生三种不同priority 的events, : consumers 必须1. 总是优先处理高priority的event, 2.同priority的events按先来 : 后到处理。 : 刚开始的设想是用priorityblockingqueue, 方便快捷 : 第一个concern是: priorityblockingqueue无法保证同priority的events能按先来后 : 到处理。 : 这个可以通过rewrite comparator解决 : 第二个concern比较大: priorityblockingqueue是用heap实现的, enqueue and : dequeue都是 log(n) 的操作,
|
m****r 发帖数: 6639 | 3 en. since she only has 3 different levels, this is how i would do it.
why do we need threadPool for this queue implementation?
西。
【在 g*****g 的大作中提到】 : 这不难呀,你需要的是实现一个自己的BlockingQueue,里面放三个 : LinkedBlockingQueue,按三个优先级,把那些方法wrap一遍。接下来你需要的是一个 : Threadpool。ThreadPoolExecutor拿过来直接用对你就够了。一个小时的活。 : 什么wait/notify统统用不到。没事把java.util.concurrent看一看,里面很多好东西。
|
g*****g 发帖数: 34805 | 4 Not for queue, but for producer/consumer. Why do you want to buy wheels and
a chassis when you can buy a car.
【在 m****r 的大作中提到】 : en. since she only has 3 different levels, this is how i would do it. : why do we need threadPool for this queue implementation? : : 西。
|
m****r 发帖数: 6639 | 5 because i like my car but i hate the wheels on the car?
i suspect she doesn't really care about the producer/consumer people.
and
【在 g*****g 的大作中提到】 : Not for queue, but for producer/consumer. Why do you want to buy wheels and : a chassis when you can buy a car.
|
p****i 发帖数: 6135 | 6 good idea.
thanks
我OO的思想还是很差啊 , 习惯性的还是C的过程型的思维。。。
西。
【在 g*****g 的大作中提到】 : 这不难呀,你需要的是实现一个自己的BlockingQueue,里面放三个 : LinkedBlockingQueue,按三个优先级,把那些方法wrap一遍。接下来你需要的是一个 : Threadpool。ThreadPoolExecutor拿过来直接用对你就够了。一个小时的活。 : 什么wait/notify统统用不到。没事把java.util.concurrent看一看,里面很多好东西。
|
p*****2 发帖数: 21240 | 7
西。
确实这样就可以了。没必要用PriorityQueue。Queue本来就按照先来后到的顺序
【在 g*****g 的大作中提到】 : 这不难呀,你需要的是实现一个自己的BlockingQueue,里面放三个 : LinkedBlockingQueue,按三个优先级,把那些方法wrap一遍。接下来你需要的是一个 : Threadpool。ThreadPoolExecutor拿过来直接用对你就够了。一个小时的活。 : 什么wait/notify统统用不到。没事把java.util.concurrent看一看,里面很多好东西。
|
p*****2 发帖数: 21240 | 8
and
不过用个thread也无所谓吧?这个应该不是关键吧?
【在 g*****g 的大作中提到】 : Not for queue, but for producer/consumer. Why do you want to buy wheels and : a chassis when you can buy a car.
|