What method call is used to tell a thread that it has the opportunity to run?
a.wait()
b.notify()
c.start()
d.run()答案是b,可我觉得c 也对,大家说说自己的看法哈
a.wait()
b.notify()
c.start()
d.run()答案是b,可我觉得c 也对,大家说说自己的看法哈
解决方案 »
- sql中查询是有结果的。但是eclipe中运行: 结果集没有当前行。
- 用ajax如何实现将数组从后台传回jsp页面中供js使用,谢谢!
- java网络通信
- 为什么我的System.in.read()不能挂起程序?
- 急,菜鸟求助!!!(在线等,问题解决马上给分)
- 谁有图书管理的源给码研究研究阿...
- java.awt & javax.swing???
- jbuilder有个编译选项,能加入混淆码,是哪个选项,请指点
- 一个简单而有趣的奇葩问题
- 高分求书!那儿有java threads(o'reilla)书下载
- 【菜鸟问题】捕获了异常后,能不能不要退出程序啊????
- 我的机器上有jdk1.42 我要装1.5 会有冲突吗?如果有怎样解决.
而b则是让线程进入lock pool,等待对象的锁被其他线程释放,一旦释放就运行所以opportunity这个词,用的有毛病
按照书上说的:
calling your thread's start() method doesn't immediately cause the thread to run ; it just
makes the thread eligible to run.The thread must still contend for CPU time with oter threads.
照这样说,start()方法也是让线程有机会运行,不过按rainly1985(鹏)的说法“start 之后就肯定会运行的,但是notify之后是有可能”,这样理解的话,start()就不是精确答案了。shenpipi(皮皮) 从调度者和被调度者的观点来看,感觉不是关键所在。两个方法的用法还是明确的,就是感觉题目有点迷糊
附notify()的用法:
The notify() method arbitrarily selects one of the threads in the monitor's wating pool and
moves it to the Seeking Lock State.
It means when can the current object can be accessed by some threads but not when the thread can run.
So b is the correct answer.If the question is changed to be what method call is used to tell a thread that it can be run? So the answer is C.
But why isnot d.
Bucause as usual, run method will not be intented to be called directed. Instend, we should call the method start, and then the thread object will call the run method to do the exactly job automatically.
What method call is used to tell a thread that it has the opportunity to run?what method call is used to tell a thread that it can be run?有区别吗?
shenpipi(皮皮)说的还有点想得通“
start 之后就肯定会运行的,但是notify之后是有可能,因为可能被等待同一个锁的其他线程抢先执行”