• 首页
  • 期刊简介
  • 编委会
  • 投稿指南
  • 收录情况
  • 杂志订阅
  • 联系我们
引用本文:崔 政,段利国.基于Java synchronized同步锁实现线程交互[J].软件工程,2018,21(2):1-3.【点击复制】
【打印本页】   【下载PDF全文】   【查看/发表评论】  【下载PDF阅读器】  
←前一篇|后一篇→ 过刊浏览
分享到: 微信 更多
基于Java synchronized同步锁实现线程交互
崔 政,段利国1,2
1.(1.太原理工大学,山西 太原 030024;2.
2.山西省电力公司平顺县供电公司,山西 长治 047400)
摘 要: Java多线程能够提高CPU利用效率,但也容易造成线程不安全、线程死锁等问题。本文详细介绍了Java 线程各状态之间的关系及其切换,并用实例展示了使用同步锁synchronized保证同一时刻只有一个线程操作同一资源, 使用wait()、notify()切换线程状态保证线程操作的前后顺序实现线程交互。理解Java线程各状态之间的关系及其切换, 能帮助用户在使用Java多线程的场景有效避免多线程带来的不安全问题。
关键词: 多线程;synchronized;线程交互
中图分类号: TP312    文献标识码: A
基金项目: 山西省重点资助教学改革项目(面向工程教育专业认证持续改进的课程设计实施方案研究,J2017017).
Realization of Thread Interaction Based on Java Synchronized
CUI Zheng,DUAN Liguo1,2
1.( 1.Taiyuan University of Technology, Taiyuan 030024, China;2.
2.Pingshun County Power Supply Company, Shanxi Power Company, Changzhi 047400, China)
Abstract: Java multi-threading can improve CPU utilization,but it can also cause problems such as thread insecurity and thread deadlock.This paper introduces in detail the relationship between Java thread states and their transitions.Java synchronized ensures that only one thread operates the same resource at the same time,using wait() and notify() to switch the thread state to ensure that thread interactions are implemented in the context of thread operations.Understanding the relationship between the states of Java threads and their switching can help users avoid effectively the unsafe problems of multi-threading in Java multi-threaded scenarios.
Keywords: multi-threading;synchronized;thread interaction


版权所有:软件工程杂志社
地址:辽宁省沈阳市浑南区新秀街2号 邮政编码:110179
电话:0411-84767887 传真:0411-84835089 Email:semagazine@neusoft.edu.cn
备案号:辽ICP备17007376号-1
技术支持:北京勤云科技发展有限公司

用微信扫一扫

用微信扫一扫