由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - thread signaling 的一个问题
相关主题
请问关于用threadPoolExecutor实现threadpool的问题?Java NIO 问题求教
文件分割的问题Signal handler, thanks
condional variable thread sync 问题两种面试: 基于历史的和面向未来的
做一些贡献:threadPool一道Trading数据结构的实现问题
Another ?: Re: Keep track # of threads[合集] JAVA请教
问个多线程的问题Comparator Accessor method for SortedSet
问一个基础问题泛型问题
求思路How to do this using JDBC?
相关话题的讨论汇总
话题: priority话题: signaling话题: thread话题: events
进入Java版参与讨论
1 (共1页)
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.

1 (共1页)
进入Java版参与讨论
相关主题
How to do this using JDBC?Another ?: Re: Keep track # of threads
Provide A Interview Question问个多线程的问题
LinkedList 问题问一个基础问题
paint()呀,repaint()呀求思路
请问关于用threadPoolExecutor实现threadpool的问题?Java NIO 问题求教
文件分割的问题Signal handler, thanks
condional variable thread sync 问题两种面试: 基于历史的和面向未来的
做一些贡献:threadPool一道Trading数据结构的实现问题
相关话题的讨论汇总
话题: priority话题: signaling话题: thread话题: events