文档介绍:目录
JAVA多线程同步机制及其应用 1
1 前言 2
线程 2
同步机制 2
2 JAVA多线程 3
线程的创建 3
继承Thread类实现多线程 3
实现Runnable接口实现多线程 3
线程管理 4
线程周期 4
线程控制 4
线程的调度 5
3 多线程同步机制 6
多线程的问题 6
JAVA同步机制 8
synchronized关键字 8
synchronized方法 10
同步机制的问题 11
wait()/notify()方法 13
4 交通灯管理系统 14
设计方法 14
具体实现 15
主要功能及类介绍 15
5 结束语 16
致谢 16
参考文献 17
附录 18
JAVA多线程同步机制及其应用
摘要介绍了JAVA线程的概念,分析了多线程和同步机制。给出了创建线程的两种方法:继承Thread类和实现runnable接口及其基本格式。详细分析了线程周期中的五种状态;线程的控制的几种基本的方法start(),stop(),sleep()等;线程的调度、优先级。结合具体实例指出了多线程存在的一些问题,探讨了实现JAVA同步机制的两种方法:synchronized关键字和synchronzied方法。给出了解决假同步和死锁的方法。介绍了多线程间通信的一种方法:wait()/notify()方法,以及该方法的主要格式,应用范围,和应用要注意的事项。通过一个具体的综合应用的实例,说明多线程在实际中的应用。
关键词多线程;同步机制;线程;线程控制;死锁
JAVA multithreading synchronized mechanism and applications
Abstract Introduced the concept of the JAVA Thread, analyze a multi-threading and the synchronized mechanism. Give establish the Thread of two kinds of methods inherit Thread and realize runnable interface and its basic format. To five kinds of state in the Thread, a few basic method of the control of the Thread, start(), stop() sleep() etc., the Thread attemper, PRI,make concrete introduction. With a concrete example to explain a little bit existent problems of multi-threadings, give the concrete contents of synchronized mechanism, two kinds of basic realizations are synchronized method and the basic format of the synchronized key word and the synchronzied method. Discussed two kinds of problems of JAVA synchronized mechanism: False synchronized and deadlock, and give understand the suggestion of these two kinds of problems definitely. Introduced a kind of method for multi-munications: Wait()/notify() method, and the main format of that method, the application, and notice with application of item. Application passed a solid example of prehensive application, explained a multi-threading Application in physically.
Keyword multi-threading;synchronized mechanism