由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - suggestions needed
相关主题
one multi-threading questionjdbc + oracle connection pooling问题
JDK Source?问个多线程的问题。
java里的时间计算问个多线程的问题
如何生产产生Java Doc的注释向能人请教
java8的default出来之后Re: How to lock a file and detect a thread is over?
JDK 9 Build b07 Early Access Build 发布[转载] 现在还有什么OS不是THREAD级调度的吗?
question on single thread & multithreadjava thread question
问个HttpClient 的问题thread independent on a single-cpu machine?
相关话题的讨论汇总
话题: threads话题: wake话题: needed话题: thread
进入Java版参与讨论
1 (共1页)
c**d
发帖数: 579
1
I am new to Java and have a problem,
I am writing a server program. Whenvever a client connects, it will create a
new thread for that client. The new thread does some work, and goes into
sleep. Every 5 minutes, all the threads wake up and send data out to clients.
How can I let all threads sleep and wake all of them up?
Any suggestions are welcome. thanks.
r*****l
发帖数: 2859
2
wait(), notify(), notifAll().

【在 c**d 的大作中提到】
: I am new to Java and have a problem,
: I am writing a server program. Whenvever a client connects, it will create a
: new thread for that client. The new thread does some work, and goes into
: sleep. Every 5 minutes, all the threads wake up and send data out to clients.
: How can I let all threads sleep and wake all of them up?
: Any suggestions are welcome. thanks.

H***a
发帖数: 189
3
read a read javax.concurrent package.

【在 r*****l 的大作中提到】
: wait(), notify(), notifAll().
c**d
发帖数: 579
4
found a solution:
all children threads call wait(), master thread setup a timer and loops thro
ugh all children and call interrupt() to wake them up

【在 H***a 的大作中提到】
: read a read javax.concurrent package.
H***a
发帖数: 189
5
CountDownLatch in JDK1.5 is exactly what you need I think.
it's in java.util.concurrent package.
There is an example in JDK's JavaDoc.
Sample usage: Here is a pair of classes in which a group of worker threads use two countdown latches:
The first is a start signal that prevents any worker from proceeding until the driver is ready for them to proceed;
The second is a completion signal that allows the driver to wait until all workers have completed.
class Driver { // ...
void main() throws Inte

【在 c**d 的大作中提到】
: found a solution:
: all children threads call wait(), master thread setup a timer and loops thro
: ugh all children and call interrupt() to wake them up

c**d
发帖数: 579
6
thanks for your suggestion, I'll try it out later

【在 H***a 的大作中提到】
: CountDownLatch in JDK1.5 is exactly what you need I think.
: it's in java.util.concurrent package.
: There is an example in JDK's JavaDoc.
: Sample usage: Here is a pair of classes in which a group of worker threads use two countdown latches:
: The first is a start signal that prevents any worker from proceeding until the driver is ready for them to proceed;
: The second is a completion signal that allows the driver to wait until all workers have completed.
: class Driver { // ...
: void main() throws Inte

1 (共1页)
进入Java版参与讨论
相关主题
thread independent on a single-cpu machine?java8的default出来之后
Thread对应的input和output问题JDK 9 Build b07 Early Access Build 发布
multi-threading guru们 (转载)question on single thread & multithread
多少个thread 就算不正常?问个HttpClient 的问题
one multi-threading questionjdbc + oracle connection pooling问题
JDK Source?问个多线程的问题。
java里的时间计算问个多线程的问题
如何生产产生Java Doc的注释向能人请教
相关话题的讨论汇总
话题: threads话题: wake话题: needed话题: thread