zoukankan      html  css  js  c++  java
  • 子线程循环10次,主线程循环100次;然后子线程循环10次,主线程循环100次,这样循环50次;

    子线程循环10次,主线程循环100次;然后子线程循环10次,主线程循环100次,这样循环50次;

    public class CircleThread {
    	
    	public static void main(String[] args) {
    		Fun fun = new Fun();
    		new Thread(()->{
    			synchronized (fun) {
    				for (int j = 0; j < 50; j++) {
    					while(fun.x != 1){
    						try {
    							fun.notify();
    							fun.wait();
    						} catch (Exception e) {
    							e.printStackTrace();
    						}
    					}
    					for (int i = 0; i < 10; i++) {
    						System.out.println(Thread.currentThread().getName() + "---> i = " + i + ";___j = " + j + ";");
    					}
    					fun.x = 2;
    					fun.notify();
    				}
    			}
    		},"Thread-A").start();
    		synchronized (fun) {
    			for (int k = 0; k < 50; k++) {
    				while(fun.x != 2){
    					try {
    						fun.notify();
    						fun.wait();
    					} catch (Exception e) {
    						e.printStackTrace();
    					}
    				}
    				for (int x = 0; x < 100; x++) {
    					System.out.println(Thread.currentThread().getName() + "---> x = " + x + ";");
    				}
    				fun.x = 1;
    			}
    		}
    	}
    }
    class Fun{
    	public int x = 1;
    }
    
  • 相关阅读:
    安装高版本的docker
    Apache JMeter汉化手册
    安装python包
    Jmeter Cluster
    doc下设置永久环境变量的好方法
    jmeter非常好的博客收藏
    mysql-学习链接
    python 脚本
    常见python快捷键
    2015年心情随笔--周围太烦躁,我想静静
  • 原文地址:https://www.cnblogs.com/kaka-qiqi/p/14837796.html
Copyright © 2011-2022 走看看