线撞 10 在多 Thread 1 CPUs 上的多 Thread 2 线程 Thread 3 在单 Thread 1 CPUs 上的多 Thread 2 线程 Thread 3
10-16 Programming in Java 多线程概念 在多 CPUs 上的多 线程 在单 CPUs 上的多 线程 Thread 3 Thread 2 Thread 1 Thread 3 Thread 2 Thread 1
低佳的状。与阅明 10- new start runnable 为 quantum dispatch (assign notify or expiration a processor) IO nofA川 3 completion running wait issue I/O c request suspend waiting sleeping suspended blocked sleep interval stop complete expires resume dead
10-17 Programming in Java 线程的状态与生命周期 new start runnable running waiting sleeping suspended blocked dead dispatch (assign a processor) quantum expiration I/O completion resume stop wait sleep suspend complete issue I/O request sleep interval expires notify or notifyAll
线佳同过与④山改 10 (I)Thread类中有关优先级的常量与方法 MAX-(10),MIN-(1),NORM-(5,default) public final void setPriority(int newPriority), newPriority必须在MN-和MAX之间 public final int getPriority() (2)线程调度 ·在当前可运行线程中选优先级别最高的运行 ·相同优先级问题
10-18 Programming in Java (1) Thread类中有关优先级的常量与方法 • MAX- (10), MIN- (1) ,NORM-(5, default) • public final void setPriority(int newPriority), newPriority 必须在 MIN- 和 MAX之间 • public final int getPriority() 线程调度与优先级 (2) 线程调度 • 在当前可运行线程中选优先级别最高的运行 • 相同优先级问题
10 ·Java中编程实现多线程有两种途径 >建立Thread类的某个子类的对象 class ThreadX extends Thread public void run //logic for the thread Thread ThreadSubclass ThreadX tx new ThreadXO; tx.start();
10-19 Programming in Java • Java中编程实现多线程有两种途径 ¾建立Thread 类的某个子类的对象 Thread ThreadSubclass class ThreadX extends Thread { public void run() { //logic for the thread } } ThreadX tx = new ThreadX(); tx.start(); 线程的创建(1)
10-2 >创建实现Runnable接口的某个类的对象 class Runnable Y implements Runnable public void run(){ //logic for the thread Runnable implements SomeSubclass RunnableY ry new RunnableYO; Thread ty new Thread(ry); ty.start();
10-20 Programming in Java class RunnableY implements Runnable { public void run() { //logic for the thread } } RunnableY ry = new RunnableY(); Thread ty = new Thread(ry); ty.start(); Runnable SomeSubclass implements 线程的创建(2) ¾ 创建实现 Runnable 接口的某个类的对象