|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
java原著中对线程的解释: Thread Scheduling In Java technology,threads are usually preemptive,but not necessarily Time-sliced(the process of giving each thread an equal amount of CPU time).It is common mistake to believe that \"preemptive\" is a fancy word for \"does time-slicing\". For the runtime on a Solaris Operating Environment platform,Java technology does not preempt threads of the same priority.However,the runtime on Microsoft Windows platforms uses time-slicing,so it preempts threads of the same priority and even threads of higher priority.Preemption is not guaranteed;however,most JVM implementations result in behavior that appears to be strictly preemptive.Across JVM implementations,there is no absolute guarantee of preemption or time-slicing.The only guarantees lie in the coder’s use of wait and sleep. The model of a preemptive scheduler is that many threads might be runnable,but only one thread is actually running.This thread continues to run until it ceases to be runnable or another thread of higher priority becomes runnable.In the latter case,the lower priority thread is preempted by the thread of higher priority,which gets a chance to run instead. A thread might cease to runnable (that is,because blocked) for a variety of reasons.The thread’s code can execute a Thread.sleep() call,deliberately asking the thread to pause for a fixed period of time.The thread might have to wait to access a resource and cannot continue until that resource become available. All thread that are runnable are kept in pools according to priority.When a blocked thread becomes runnable,it is placed back into the appropriate runnable pool.Threads from the highest priority nonempty pool are given CPU time. The last sentence is worded loosed because: 热心网友翻译的版本:(来自www.cn-java.com)
从学java到现在,多线程设计一直困扰着我,也许是自己的e文太差,也许是自己天生愚笨,无论原版的e文和网友翻译的中文版,都拜读了无数遍了,而且涉及java多线程的开发也搞了一段时间,然而自己却还不能真正体会线程的深刻含义。“Preemption is not guaranteed;however,most JVM implementations result in behavior that appears to be strictly preemptive”,对于java多线程的抢占和时间片,不能说其为绝对的抢占,然而在JVM中,却表现了严格的抢占。对于目前的多任务操作系统,多线程的设计开发可以说让我体会了从前使用单线程语言无法比拟的交互性能和实时控制性,一度让我为其着迷,然而我一直疑惑的是到底这个多线程对系统的利用如何?linux/unix也好,windows也好,都有其独特的运行机制,而且多线程是否好用呢?真的那么易用?从自己学习java线程以来,犯的错误比自己学c多得多,可能是自己太笨了,无法领悟这么优秀语言的强盛性能。对于同步对象的恒定性和跨类的同步对象,让我确实够头疼的,总是犯些低级错误。 通过用了那么一段时间的java多线程,我还是感觉c++更灵活些,虽然java把多线程嵌入到了语言之中。在《Taming Java Threads 》一书中,对java线程的一些缺陷进行了分析,看了后,我认为对于一种面向对象的语言来说,多线程的设计的确难以满意面向对象。别的不说,无非就是个run()方式,呵呵.....学艺不精,是自己活该倒霉,不能怪别人。不过,java能使用wait(),notify()等机制来控制线程,对我们这些脑子不好使得人可是大大的恩赐阿。 返回类别: 教程 上一教程: 在Eclipse上搭建Nokia手机的J2ME开发环境 下一教程: 简述JAVA对象的产生与使用 您可以阅读与"java多线程,什么时候让我跨过你高高的门槛"相关的教程: · 初学Java写的第一个多线程程序 · JAVA多线程编程详解 · Java多线程程序设计 · Java线程入门??什么是线程 · Java多线程编程详解 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |