第七章 线程(4学时).pptVIP

  • 13
  • 0
  • 约1.89万字
  • 约 100页
  • 2017-02-03 发布于湖北
  • 举报
第七章 线程 目 录 7.1 多线程编程基础 7.2 线程的生命周期及调度 7.3 线程间的数据共享 7.4 线程间的同步控制 7.5 线程间的通信 7.6 后台线程 7.7 死锁 7.8控制线程的生命 7.1 多线程编程基础 进程:一个独立程序的每一次运行; 一、Thread类 封装了Java程序中一个线程对象需要拥有的属性和方法; 例7-1:在新线程中完成计算某个整数的阶乘。 修改后运行结果: main thread starts new thread stared The factorial of 10 is 3628800 new thread ends main thread ends 运行结果说明: 新线程结束后main线程才结束 例7-2:创建3个新线程,每个线程睡眠一段时间(0~6秒),然后结束。 运行结果: Starting threads Threads started, main ends thread1 going to sleep for 3519 thread2 going to sleep for 1689 thread3 going to sleep for 5565 thread2 finished thread1 finished thread3 finished 二、Runnable接口 相对于Thread类, Runnable更适合于多个

文档评论(0)

1亿VIP精品文档

相关文档