Topic: 求教wait(),notify()的应用方法? |
Print this page |
1.求教wait(),notify()的应用方法? | Copy to clipboard |
Posted by: frankychenCYF Posted on: 2005-06-11 03:14 例如:线程 A,B,C 依次启动,它们都要使用一个资源X。A先用,用了一半,A调用了wait(),进入等待状态,且释放了X的锁;接着B就获得X,B用了一半也调用了wait();C再调用X,C用了一半,也调用了wait(),然后程序就死在那里了,因为没有notify,3个线程都wait了,醒不了! 那么,该怎么调用notify()? 谁调用?是正在使用资源的线程调用,还是那些在等待使用资源的线程调用? 在哪里调用?什么时候调用呢?就是在程序的什么位置调用? 如果要实现A,B,C轮流使用X,该怎么使用wait notify机制呢? 先谢过大家了~~ |
2.Re:求教wait(),notify()的应用方法? [Re: frankychenCYF] | Copy to clipboard |
Posted by: floater Posted on: 2005-06-11 04:15 check taming java thread book. |
3.Re:求教wait(),notify()的应用方法? [Re: frankychenCYF] | Copy to clipboard |
Posted by: chengbd Posted on: 2005-06-11 17:38 问题大了些,一两句说不清,找书看吧 |
4.Re:求教wait(),notify()的应用方法? [Re: frankychenCYF] | Copy to clipboard |
Posted by: graying Posted on: 2005-06-22 09:16 曾经在外面看到过一篇文章将并发的,讲的蛮好的,就是我的收藏夹里面怎么找不到了呢……? |
5.Re:求教wait(),notify()的应用方法? [Re: frankychenCYF] | Copy to clipboard |
Posted by: omegalsw1024 Posted on: 2005-06-25 18:18 A使用资源,时间片结束,A调用wait()方法,再调用notify(),参数为B,或C B重复A的行为,然后是C,再是A,如此反复,可实现A,B,c的循环使用资源 |
6.Re:求教wait(),notify()的应用方法? [Re: frankychenCYF] | Copy to clipboard |
Posted by: jameszhang Posted on: 2005-06-25 22:15 同步不就可以吗,还用wait干什么? 如果 A使用资源需要B的操作,还可以使用wait |
7.Re:求教wait(),notify()的应用方法? [Re: frankychenCYF] | Copy to clipboard |
Posted by: ranchgirl Posted on: 2005-06-29 21:18 You really need to read a book, then do your design to void deadlock. What you said is a design definitely going to deadlock. Your IE or other windows probably die or no response sometimes. The reason is very possible a deadlock or racing condition. Thread and concurrent programming is a big topic, need to learn it seriously, need to learn it for a long time, and need to learn it for your programming life time. |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |