Example9_16

news/2024/7/4 0:53:28 标签: thread, class, string, 工作
class="baidu_pl">
class="article_content clearfix">
class="htmledit_views">

 package itat;

public class Example9_16 {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub

  MyThread class="tags" href="/tags/THREAD.html" title=thread>thread1=new MyThread();
  class="tags" href="/tags/THREAD.html" title=thread>thread1.setName("张三");
  class="tags" href="/tags/THREAD.html" title=thread>thread1.start();
  YourThread class="tags" href="/tags/THREAD.html" title=thread>thread2=new YourThread(class="tags" href="/tags/THREAD.html" title=thread>thread1);
  class="tags" href="/tags/THREAD.html" title=thread>thread2.setName("李四");
  class="tags" href="/tags/THREAD.html" title=thread>thread2.start();
 }

}
class  MyThread extends Thread{
 int i=0;
 public void run(){
  while(true){
   i++;
   System.out.println("我的名字是"+getName()+"i="+i);
   if(i==10){
    guaqi();
   }
   try {
    Thread.sleep(1000);
   } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
 }
 public synchronized void guaqi() {
  // TODO Auto-generated method stub
  try {
   wait();
  } catch (InterruptedException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
 }
 public synchronized void huifu(){
  notifyAll();
 }
 
}
class YourThread extends Thread{
 int m=0;
 MyThread otherThread;
 YourThread(MyThread a){
  otherThread=a;
  
 }
 public void run(){
  while(true){
   m++;
   System.out.println("我的名字是"+getName()+"m="+m);
   if(m==20){
    System.out.println("恢复线程:"+otherThread.getName());
    System.out.println(getName()+"停止工作");
    otherThread.huifu();
    return;
    
   }
   try {
    Thread.sleep(1000);
   } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
 }
}


http://www.niftyadmin.cn/n/656208.html

相关文章

mysql mybatis 条件批量插入(条件满足即插入,否则不插入)

在mysql中插入一或者多条记录的时候,要求某个字段的值唯一,但是该字段没有添加唯一性索引,可用from dual解决。 1 2 3 4 5 select * from ( select 2015080109 a,2 b,4 c,5 d from dual union select 2015080106 a,2 b,4 c,5 d from dual ) …

IDEA中使用git合并分支的过程报错:cant checkout because of unmerged files

使用idea的git插件控制代码分支合并时,由于操作不当,报错了,控制台报错如下: cant checkout because of unmerged files,you have to resolve all merge conflicts before checkout. 仔细回想报错的起因,经过大概是这样的:首先,远程仓库里面的代码版本是很老了,而本地的代码版…

maven引用本地sql server驱动 和oracle 驱动

1, 下载驱动 网盘地址: 链接: https://pan.baidu.com/s/1EjA3icUp4O7fznxT1LGvpQ 提取码: 955w 复制这段内容后打开百度网盘手机App,操作更方便哦 2. 切换到对应的目录执行: mvn install:install-file -Dfilesqljdbc4-4.0.jar -DgroupIdcom.sqlserver -Dartifac…

Redis操作命令大全

一、key pattern 查询相应的key (1)redis允许模糊查询key  有3个通配符 *、?、[] (2)randomkey:返回随机key   (3)type key:返回key存储的类型 (4)exis…

redisson-spring-boot-starter

redisson-spring-boot-starter spring boot 配置: spring.redis.redisson.config: classpath:redisson-beta.yml 或者 spring.redis.redisson.config: classpath:redisson-product.yml 配置类: org.redisson.spring.starter.RedissonAutoConfiguration 目前有很多项目还在使…

图像直方图的均衡化

2019-05-27 11:16:45 直方图均衡化是用于提高图像对比度一种方式; 直方图均衡化涉及到几个概念如下:图像直方图:表示图像中每一灰度出现频次的统计关系,横轴代表灰度值,纵轴代表该灰度值在整张图片中出现次数;概率密度…

Ubuntu18.04安装JDK1.8和maven3

康雨城 2019-05-20 18:36:03 570 已收藏 2 分类专栏: 自学 文章标签: JDK Ubuntu18 maven 版权 背景 我们在Ubuntu16或14上面安装JDK1.8一般需要手动安装,并配置环境。 但是ubuntu18却不然,在ubuntu18里面默认的JDK是1.8,maven…

MyISAM和InnoDB

MyISAM和InnoDB MyISAM是MySQL的默认数据库引擎(5.5版之前),由早期的ISAM(Indexed Sequential Access Method:有索引的顺序访问方法)所改良。虽然性能极佳,但却有一个缺点:不支持事务…