天下棋牌下载

  • <tr id='2y59t'><strong id='2y59t'></strong><small id='2y59t'></small><button id='2y59t'></button><li id='2y59t'><noscript id='2y59t'><big id='2y59t'></big><dt id='2y59t'></dt></noscript></li></tr><ol id='2y59t'><option id='2y59t'><table id='2y59t'><blockquote id='2y59t'><tbody id='2y59t'></tbody></blockquote></table></option></ol><u id='2y59t'></u><kbd id='2y59t'><kbd id='2y59t'></kbd></kbd>

    <code id='2y59t'><strong id='2y59t'></strong></code>

    <fieldset id='2y59t'></fieldset>
          <span id='2y59t'></span>

              <ins id='2y59t'></ins>
              <acronym id='2y59t'><em id='2y59t'></em><td id='2y59t'><div id='2y59t'></div></td></acronym><address id='2y59t'><big id='2y59t'><big id='2y59t'></big><legend id='2y59t'></legend></big></address>

              <i id='2y59t'><div id='2y59t'><ins id='2y59t'></ins></div></i>
              <i id='2y59t'></i>
            1. <dl id='2y59t'></dl>
              1. <small id='enwi8'></small><noframes id='enwi8'>

              2. <tfoot id='enwi8'></tfoot>

                  <legend id='enwi8'><style id='enwi8'><dir id='enwi8'><q id='enwi8'></q></dir></style></legend>
                  <i id='enwi8'><tr id='enwi8'><dt id='enwi8'><q id='enwi8'><span id='enwi8'><b id='enwi8'><form id='enwi8'><ins id='enwi8'></ins><ul id='enwi8'></ul><sub id='enwi8'></sub></form><legend id='enwi8'></legend><bdo id='enwi8'><pre id='enwi8'><center id='enwi8'></center></pre></bdo></b><th id='enwi8'></th></span></q></dt></tr></i><div id='enwi8'><tfoot id='enwi8'></tfoot><dl id='enwi8'><fieldset id='enwi8'></fieldset></dl></div>

                      <bdo id='enwi8'></bdo><ul id='enwi8'></ul>

                    1. <tr id='h9abj'><strong id='h9abj'></strong><small id='h9abj'></small><button id='h9abj'></button><li id='h9abj'><noscript id='h9abj'><big id='h9abj'></big><dt id='h9abj'></dt></noscript></li></tr><ol id='h9abj'><option id='h9abj'><table id='h9abj'><blockquote id='h9abj'><tbody id='h9abj'></tbody></blockquote></table></option></ol><u id='h9abj'></u><kbd id='h9abj'><kbd id='h9abj'></kbd></kbd>

                      <code id='h9abj'><strong id='h9abj'></strong></code>

                      <fieldset id='h9abj'></fieldset>
                            <span id='h9abj'></span>

                                <ins id='h9abj'></ins>
                                <acronym id='h9abj'><em id='h9abj'></em><td id='h9abj'><div id='h9abj'></div></td></acronym><address id='h9abj'><big id='h9abj'><big id='h9abj'></big><legend id='h9abj'></legend></big></address>

                                <i id='h9abj'><div id='h9abj'><ins id='h9abj'></ins></div></i>
                                <i id='h9abj'></i>
                              1. <dl id='h9abj'></dl>
                                1. 当前位置 : IT培训网 > Java开发 > Java教程 > Java开发中线程挂起、恢复和终止的办法

                                  Java开发中线程挂起、恢复和终止的办法

                                  时间:2015-08-30 16:08:44  来源:Java培训网  作者:IT培训网  已有:名学员访问该课程
                                  Thread类的suspend()方法在Java2中不被赞成,因为suspend()有时会造成严重的系统故障。假定对关键的数据结构的一个线程被锁定的情况,如果该线程在那里挂起,这些锁定的线程并没有放弃对资源的控制。其他的等待这些资源的线程可能

                                  天下棋牌下载 BENJIEJIESHAODEJavaZHISHIDIANBIJIAOJIANDAN,ZHIYAODAJIAYONGXINSHUDUJIYIJIKEXUEHUILE,XIAMIANJIUSHIDUIJavaKAIFAZHONGXIANCHENGGUAQI、HUIFUHEZHONGZHIFANGMIANDEJIESHAO,HAOHAOXUEXIBA!

                                  YOUSHI,XIANCHENGDEGUAQISHIHENYOUYONGDE。LIRU,YIGEDULIDEXIANCHENGKEYIYONGLAIXIANSHIDANGRIDESHIJIAN。RUGUOYONGHUBUXIWANGYONGSHIZHONG,XIANCHENGBEIGUAQI。ZAIRENHEQINGXINGXIA,GUAQIXIANCHENGSHIHENJIANDANDE,YIDANGUAQI,ZHONGXINQIDONGXIANCHENGYESHIYIJIANJIANDANDESHI。

                                  GUAQI,ZHONGZHIHEHUIFUXIANCHENGJIZHIZAIJava 2HEZAOQIBANBENZHONGYOUSUOBUTONG。JINGUANNIYUNYONGJava 2DETUJINGBIANXIEDAIMA,NIRENGXULEJIEZHEIXIECAOZUOZAIZAOQIJavaHUANJINGXIASHIRUHEWANCHENGDE。LIRU,NIYEXUXUYAOGENGXINHUOWEIHULAODEDAIMA。NIYEXUYAOLEJIEWEISHENMEJava 2HUIYOUZHEIYANGDEBIANHUA。YINWEIZHEIXIEYUANYIN,XIAMIANNEIRONGMIAOSHULEZHIXINGXIANCHENGKONGZHIDEYUANSHIFANGFA,JIEZHESHIJava 2DEFANGFA。

                                  Java 1.1或更早版本的线程的挂起、恢复和终止

                                  XIANYUJava2DEBANBEN,CHENGXUYONGThread DINGYIDEsuspend() HE resume() LAIZANTINGHEZAIQIDONGXIANCHENG。TAMENDEXINGSHIRUXIA:

                                  天下棋牌下载 final void suspend( )

                                  final void resume( )

                                  XIAMIANDECHENGXUMIAOSHULEZHEIXIEFANGFA:

                                  天下棋牌下载 // Using suspend() and resume().

                                  class NewThread implements Runnable {

                                  String name; // name of thread

                                  Thread t;

                                  天下棋牌下载 NewThread(String threadname) {

                                  天下棋牌下载 name = threadname;

                                  天下棋牌下载 t = new Thread(this, name);

                                  System.out.println("New thread: " + t);

                                  t.start(); // Start the thread

                                  }

                                  天下棋牌下载 // This is the entry point for thread.

                                  天下棋牌下载 public void run() {

                                  try {

                                  for(int i = 15; i > 0; i--) {

                                  System.out.println(name + ": " + i);

                                  Thread.sleep(200);

                                  }

                                  天下棋牌下载 } catch (InterruptedException e) {

                                  天下棋牌下载 System.out.println(name + " interrupted.");

                                  }

                                  System.out.println(name + " exiting.");

                                  }

                                  }

                                  class SuspendResume {

                                  天下棋牌下载 public static void main(String args[]) {

                                  NewThread ob1 = new NewThread("One");

                                  NewThread ob2 = new NewThread("Two");

                                  try {

                                  天下棋牌下载 Thread.sleep(1000);

                                  ob1.t.suspend();

                                  天下棋牌下载 System.out.println("Suspending thread One");

                                  Thread.sleep(1000);

                                  天下棋牌下载 ob1.t.resume();

                                  System.out.println("Resuming thread One");

                                  ob2.t.suspend();

                                  System.out.println("Suspending thread Two");

                                  天下棋牌下载 Thread.sleep(1000);

                                  ob2.t.resume();

                                  System.out.println("Resuming thread Two");

                                  } catch (InterruptedException e) {

                                  天下棋牌下载 System.out.println("Main thread Interrupted");

                                  }

                                  // wait for threads to finish

                                  try {

                                  System.out.println("Waiting for threads to finish.");

                                  天下棋牌下载 ob1.t.join();

                                  ob2.t.join();

                                  } catch (InterruptedException e) {

                                  System.out.println("Main thread Interrupted");

                                  }

                                  System.out.println("Main thread exiting.");

                                  }

                                  }

                                  天下棋牌下载 CHENGXUDEBUFENSHUCHURUXIA:

                                  New thread: Thread[One,5,main]

                                  One: 15

                                  天下棋牌下载 New thread: Thread[Two,5,main]

                                  Two: 15

                                  One: 14

                                  Two: 14

                                  One: 13

                                  Two: 13

                                  One: 12

                                  Two: 12

                                  One: 11

                                  Two: 11

                                  Suspending thread One

                                  Two: 10

                                  Two: 9

                                  Two: 8

                                  Two: 7

                                  Two: 6

                                  Resuming thread One

                                  Suspending thread Two

                                  One: 10

                                  One: 9

                                  One: 8

                                  One: 7

                                  One: 6

                                  天下棋牌下载 Resuming thread Two

                                  天下棋牌下载 Waiting for threads to finish.

                                  Two: 5

                                  One: 5

                                  Two: 4

                                  One: 4

                                  Two: 3

                                  One: 3

                                  Two: 2

                                  One: 2

                                  Two: 1

                                  One: 1

                                  Two exiting.

                                  One exiting.

                                  Main thread exiting.

                                   

                                  ThreadLEITONGYANGDINGYILEstop() LAIZHONGZHIXIANCHENG。TADEXINGSHIRUXIA:

                                  天下棋牌下载 void stop( )

                                  天下棋牌下载 YIDANXIANCHENGBEIZHONGZHI,TABUNENGBEIresume() HUIFUJIXUYUNXING。

                                  Java 2中挂起、恢复和终止线程

                                  天下棋牌下载 ThreadDINGYIDEsuspend(),resume()HEstop()FANGFAKANQILAISHIGUANLIXIANCHENGDEWANMEIDEHEFANGBIANDEFANGFA,TAMENBUNENGYONGYUXINJavaBANBENDECHENGXU。XIAMIANSHIQIZHONGDEYUANYIN。ThreadLEIDEsuspend()FANGFAZAIJava2ZHONGBUBEIZANCHENG,YINWEIsuspend()YOUSHIHUIZAOCHENGYANZHONGDEXITONGGUZHANG。JIADINGDUIGUANJIANDESHUJUJIEGOUDEYIGEXIANCHENGBEISUODINGDEQINGKUANG,RUGUOGAIXIANCHENGZAINEILIGUAQI,ZHEIXIESUODINGDEXIANCHENGBINGMEIYOUFANGQIDUIZIYUANDEKONGZHI。QITADEDENGDAIZHEIXIEZIYUANDEXIANCHENGKENENGSISUO。

                                  天下棋牌下载 Resume()FANGFATONGYANGBUBEIZANTONG。TABUYINQIWENTI,DANBUNENGLIKAIsuspend()FANGFAERDULISHIYONG。ThreadLEIDEstop()FANGFATONGYANGZAIJava 2ZHONGSHOUDAOFANDUI。ZHEISHIYINWEIGAIFANGFAKENENGDAOZHIYANZHONGDEXITONGGUZHANG。SHEXIANGYIGEXIANCHENGZHENGZAIXIEYIGEJINGMIDEZHONGYAODESHUJUJIEGOUQIEJINWANCHENGYIGELINGTOU。RUGUOGAIXIANCHENGZAICIKEZHONGZHI,ZESHUJUJIEGOUKENENGHUITINGLIUZAIBENGKUIZHUANGTAI。

                                  YINWEIZAIJava 2ZHONGBUNENGSHIYONGsuspend(),resume()HEstop() FANGFALAIKONGZHIXIANCHENG,NIYEXUHUIXIANGNEIJIUMEIYOUBANFALAITINGZHI,HUIFUHEJIESHUXIANCHENG。QISHIBURAN。XIANGFAN,XIANCHENGBIXUBEISHEJIYISHIrun() FANGFADINGQIJIANCHAYILAIPANDINGXIANCHENGSHIFOUYINGGAIBEIGUAQI,HUIFUHUOZHONGZHITAZIJIDEZHIXING。YOUDAIBIAOXINGDE,ZHEIYOUJIANLIYIGEZHISHIXIANCHENGZHUANGTAIDEBIAOZHIBIANLIANGLAIWANCHENG。ZHIYAOGAIBIAOZHISHEWEI“running”,run()FANGFABIXUJIXURANGXIANCHENGZHIXING。RUGUOBIAOZHIWEI“suspend”,XIANCHENGBIXUZANTING。RUOSHEWEI“stop”,XIANCHENGBIXUZHONGZHI。

                                  DANGRAN,BIANXIEZHEIYANGDEDAIMAYOUHENDUOFANGFA,DANZHONGXINZHUTIDUISUOYOUDECHENGXUYINGGAISHIXIANGTONGDE。

                                  XIAMIANDELITICHANSHULECONGObjectJICHENGDEwait()HEnotify()FANGFAZENYANGKONGZHIXIANCHENGDEZHIXING。GAILIYUQIANMIANJIANGGUODECHENGXUHENXIANG。RANER,BUBEIZANTONGDEFANGFADOUMEIYOUYONGDAO。RANGWOMENSIKAOCHENGXUDEZHIXING。

                                  NewTread LEIBAOHANLEYONGLAIKONGZHIXIANCHENGZHIXINGDEBUERXINGDESHILIBIANLIANGsuspendFlag。TABEIGOUZAOHANSHUCHUSHIHUAWEIfalse。Run()FANGFABAOHANYIGEJIANCEsuspendFlag DETONGBUSHENGMINGDEKUAI。RUGUOBIANLIANGSHItrue,wait()FANGFABEIDIAOYONGYIGUAQIXIANCHENG。Mysuspend()FANGFASHEZHIsuspendFlagWEItrue。Myresume()FANGFASHEZHIsuspendFlagWEIfalseBINGQIEDIAOYONGnotify()FANGFALAIHUANQIXIANCHENG。ZUIHOU,main()FANGFABEIXIUGAIYIDIAOYONGmysuspend()HEmyresume()FANGFA。

                                  // Suspending and resuming a thread for Java2

                                  class NewThread implements Runnable {

                                  String name; // name of thread

                                  Thread t;

                                  boolean suspendFlag;

                                  NewThread(String threadname) {

                                  name = threadname;

                                  t = new Thread(this, name);

                                  System.out.println("New thread: " + t);

                                  天下棋牌下载 suspendFlag = false;

                                  天下棋牌下载 t.start(); // Start the thread

                                  }

                                  天下棋牌下载 // This is the entry point for thread.

                                  public void run() {

                                  try {

                                  天下棋牌下载 for(int i = 15; i > 0; i--) {

                                  天下棋牌下载 System.out.println(name + ": " + i);

                                  天下棋牌下载 Thread.sleep(200);

                                  synchronized(this) {

                                  天下棋牌下载 while(suspendFlag) {

                                  wait();

                                  }

                                  }

                                  }

                                  } catch (InterruptedException e) {

                                  System.out.println(name + " interrupted.");

                                  }

                                  System.out.println(name + " exiting.");

                                  }

                                  void mysuspend() {

                                  天下棋牌下载 suspendFlag = true;

                                  }

                                  天下棋牌下载 synchronized void myresume() {

                                  suspendFlag = false;

                                  notify();

                                  }

                                  }

                                  class SuspendResume {

                                  天下棋牌下载 public static void main(String args[]) {

                                  NewThread ob1 = new NewThread("One");

                                  天下棋牌下载 NewThread ob2 = new NewThread("Two");

                                  try {

                                  Thread.sleep(1000);

                                  ob1.mysuspend();

                                  System.out.println("Suspending thread One");

                                  Thread.sleep(1000);

                                  ob1.myresume();

                                  天下棋牌下载 System.out.println("Resuming thread One");

                                  天下棋牌下载 ob2.mysuspend();

                                  天下棋牌下载 System.out.println("Suspending thread Two");

                                  天下棋牌下载 Thread.sleep(1000);

                                  天下棋牌下载 ob2.myresume();

                                  天下棋牌下载 System.out.println("Resuming thread Two");

                                  天下棋牌下载 } catch (InterruptedException e) {

                                  天下棋牌下载 System.out.println("Main thread Interrupted");

                                  }

                                  // wait for threads to finish

                                  try {

                                  System.out.println("Waiting for threads to finish.");

                                  ob1.t.join();

                                  天下棋牌下载 ob2.t.join();

                                  } catch (InterruptedException e) {

                                  System.out.println("Main thread Interrupted");

                                  }

                                  System.out.println("Main thread exiting.");

                                  }

                                  }

                                  GAICHENGXUDESHUCHUYUQIANMIANDECHENGXUXIANGTONG。CISHUDEHOUMIANBUFEN,NIJIANGKANDAOYONGJava 2JIZHIKONGZHIXIANCHENGDEGENGDUOLIZI。JINGUANZHEIZHONGJIZHIBUXIANGLAOFANGFANEIYANG“GANJING”,RANER,TASHIQUEBAOYUNXINGSHIBUFASHENGCUOWUDEFANGFA。TASHISUOYOUXINDEDAIMABIXUCAIYONGDEFANGFA。

                                  SUIRAN“avaXIANCHENGDEGUAQI、HUIFUHEZHONGZHI”ZHISHIDIANBIJIAOJIANDAN,KEJICHUBUTONG,NANDUYEBUTONG,XIWANGGEWEIXIAOPENYOUYONGXINXUEXILE,XUXINSHIRENJINBU,HAOHAOXUEXIZONGSHIHAODE。

                                  顶一下
                                  (0)
                                  0%
                                  踩一下
                                  (0)
                                  0%
                                  ------分隔线----------------------------
                                  ------分隔线----------------------------
                                  Java教程
                                  1、Java 概述
                                  1.1 Java语言概述
                                  1.2 Java虚拟机以及跨平台原理
                                  1.3 Java的主要就业方向
                                  1.4 Java的不同版本
                                  1.5 Java开发环境搭建
                                  1.6 第一个Java程序示例
                                  1.7 Java类和对象的概念
                                  1.8 Java类库及其组织结构
                                  1.9 Java import
                                  2、Java 语法基础
                                  2.1 Java数据类型以及变量的定义
                                  2.2 Java数据类型转换
                                  2.3 Java运算符
                                  2.4 Java流程控制
                                  2.5 Java数组的定义和使用
                                  2.6 Java字符串(String)
                                  2.7 Java StringBuffer与StringBuider
                                  2.8 强调一下编程风格
                                  3、Java 类与对象
                                  3.1 Java类的定义及其实例化
                                  3.2 Java访问修饰符
                                  3.3 Java变量的作用域
                                  3.4 Java this关键字详解
                                  3.5 Java方法重载
                                  3.6 Java类的基本运行顺序
                                  3.7 Java包装类、拆箱和装箱详解
                                  3.8 再谈Java包
                                  3.9 源文件的声明规则
                                  4、Java 继承和多态
                                  4.1 继承的概念与实现
                                  4.2 Java super关键字
                                  4.3 继承中的方法的覆盖和重载
                                  4.4 多态和动态绑定
                                  4.5 instanceof 运算符
                                  4.6 多态对象的类型转换
                                  4.7 Java static关键字
                                  4.8 Java final关键字
                                  4.9 Java Object类
                                  5、面向对象高级特性
                                  5.1 Java内部类及其实例化
                                  5.2 内部类的分类
                                  5.3 抽象类的概念和使用
                                  5.4 接口的概念和使用
                                  5.5 接口和抽象类的区别
                                  5.6 Java 泛型
                                  5.7 泛型通配符和类型参数的范围
                                  6、异常处理
                                  6.1 异常处理基础
                                  6.2 异常类型Java语言中常见的异常类型有哪些
                                  6.3 未被捕获的异常
                                  6.4 try和catch的使用
                                  6.5 多重catch语句的使用
                                  6.6 try语句的嵌套
                                  6.7 throw:异常的抛出
                                  6.8 throws子句
                                  6.9 finally块
                                  6.10 Java的内置异常
                                  6.11 创建自己的异常子类
                                  6.12 断言
                                  7、线程编程
                                  7.1 线程的概念
                                  7.2 Java线程模型
                                  7.3 主线程
                                  7.4 创建线程
                                  7.5 创建多线程
                                  7.6 isAlive()和join()的使用
                                  7.7 线程优先级
                                  7.8 线程同步
                                  7.9 线程间通信
                                  7.10 线程死锁
                                  7.11 线程的挂起、恢复和终止
                                  8、输入输出(IO)操作
                                  8.1 输入输出基本概念
                                  8.2 面向字符的输入流
                                  8.3 面向字符的输出流
                                  8.4 面向字节的输入输出流
                                  8.5 面向字节流的应用
                                  8.6 文件与目录管理
                                  8.7 文件的随机读写
                                  8.8 文件的压缩处理
                                  9、常用类库、向量与哈希
                                  9.1 Java基础类库
                                  9.2 Object类
                                  9.3 Java语言包(java.lang)简介
                                  9.4 日期和时间类
                                  9.5 向量及其应用
                                  9.6 哈希表及其应用
                                  10、图形界面(GUI)设计
                                  10.1 图形界面设计基础
                                  10.2 框架窗口
                                  10.3 标签、按钮和按钮事件
                                  10.4 面板
                                  10.5 布局设计
                                  10.6 文本框和文本区
                                  10.7 文本框和文本区的输入输出
                                  10.8 选择框和单选按钮
                                  10.9 列表和组合框
                                  10.10 菜单
                                  10.11 对话框
                                  10.12 滚动条
                                  10.13 鼠标事件
                                  10.14 键盘事件
                                  11、图形、图像与多媒体
                                  11.1 绘图基础
                                  11.2 设置字型和颜色
                                  11.3 绘图模式
                                  11.4 Graphics类的绘图方法
                                  11.5 Graphics2D类的绘图方法
                                  11.6 图像处理基础
                                  11.7 图像缓冲技术
                                  11.8 多媒体基础
                                  12、网络与数据库编程
                                  12.1 IP地址和InetAddress类
                                  12.2 统一资源定位符
                                  12.3 套接字(Socket)
                                  12.4 数据库连接
                                  12.5 几个重要的类和接口
                                  12.6 数据库查询
                                  12.7 数据库更新
                                  12.8 插入记录
                                  12.9 修改记录
                                  12.10 删除记录

                                  京梦棋牌 - Java开发中线程挂起、恢复和终止的办法-IT培训网 乐酷棋牌---天下棋牌下载_欢迎您 疯狂牛牛安卓---天下棋牌下载_欢迎您 娱乐正规网址-Welcome 升机棋牌---天下棋牌下载_Welcome