标签:type oid pre wait div 图片 void color img
package datatype; public class demo { static final Object object = new Object(); public static void main(String[] args) { Thread t1 = new Thread(new Runnable() { @Override public void run() { for (int i = 1; i < 51; i++) { System.out.print(i); if (i % 2 == 0) { synchronized (object) { object.notify(); try { object.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } } } }); Thread t2 = new Thread(new Runnable() { @Override public void run() { char word = ‘A‘; for (int i = 0; i < 27; i++) { System.out.print(word); word++; synchronized (object) { object.notify(); try { object.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } } }); t2.start(); t1.start(); } }
标签:type oid pre wait div 图片 void color img
原文地址:https://www.cnblogs.com/excellencesy/p/11828297.html