2017-2018-2 《Java程序设计》第八周学习总结
------------------------------------------------------------------------------------------------------
教程内容总结
1:进程与线程
对于二者的概念,都与程序的概念相关。
程序:静态的代码,应用软件执行的蓝本。
进程:程序的一次动态执行过程,对应了操作系统从代码加载-->执行-->执行消亡的过程。
(操作系统可同时管理1个或多个进程,并轮流执行)
线程:进程的更小单位,一个进程的动态进行会产生多个线程。线程也有一个动态的从产
生至消亡的过程。二者属于包含关系。
2:主线程
发现main方法后启动的一个线程,负责执行main方法,称之为"主线程".
(1 && 2)
① 线程的四个状态
新建-->运行-->中断-->死亡
(因为进程是轮流切换的,能够都占用CPU,也会导致线程的中断。)
②线程的常用方法
1: start() 2:run() 3: sleep(int millsecond) 4:isAlive() 5:currentThread() 6:interrupt
3:Thread类
① 使用Thread创建线程的构建方法: Thread(Runnable target)
(参数是Runnable类型的接口,实际例子可参考例题Example12_3.java)
代码托管