Hello World

this is a test lalallalalalal

这是另外一条测试,啦啦啦啦啦啦

这是图片测试,啦啦啦啦(图片来自网络)

01

这是代码测试,咦,怎么添加代码呢哭泣的脸

   1:   
   2:  public class ProducerConsumer {
   3:      public static void main(String[] args) {
   4:          SyncStack ss = new SyncStack();
   5:          Producer p = new Producer(ss);
   6:          Consumer c = new Consumer(ss);
   7:          new Thread(p).start();
   8:          new Thread(p).start();
   9:          new Thread(p).start();
  10:          new Thread(c).start();
  11:      }
  12:  }
  13:   
  14:  class WoTou {
  15:      int id;
  16:      WoTou(int id) {
  17:          this.id = id;
  18:      }
  19:      public String toString() {
  20:          return "WoTou : " + id;
  21:      }
  22:  }
  23:   
  24:  class SyncStack {
  25:      int index = 0;
  26:      WoTou[] arrWT = new WoTou[6];
  27:  
  28:      public synchronized void push(WoTou wt) {
  29:          while(index == arrWT.length) {
  30:              try {
  31:                  this.wait();
  32:              } catch (InterruptedException e) {
  33:                  e.printStackTrace();
  34:              }
  35:          }
  36:          this.notifyAll();
  37:          arrWT[index] = wt;
  38:          index ++;
  39:      }
  40:  
  41:      public synchronized WoTou pop() {
  42:          while(index == 0) {
  43:              try {
  44:                  this.wait();
  45:              } catch (InterruptedException e) {
  46:                  e.printStackTrace();
  47:              }
  48:          }
  49:          this.notifyAll();
  50:          index--;
  51:          return arrWT[index];
  52:      }
  53:  }
  54:   
  55:  class Producer implements Runnable {
  56:      SyncStack ss = null;
  57:      Producer(SyncStack ss) {
  58:          this.ss = ss;
  59:      }
  60:  
  61:      public void run() {
  62:          for(int i=0; i<20; i++) {
  63:              WoTou wt = new WoTou(i);
  64:              ss.push(wt);
  65:              System.out.println("生产了:" + wt);
  66:              try {
  67:                  Thread.sleep((int)(Math.random() * 200));
  68:              } catch (InterruptedException e) {
  69:                  e.printStackTrace();
  70:              }
  71:          }
  72:      }
  73:  }
  74:   
  75:  class Consumer implements Runnable {
  76:      SyncStack ss = null;
  77:      Consumer(SyncStack ss) {
  78:          this.ss = ss;
  79:      }
  80:  
  81:      public void run() {
  82:          for(int i=0; i<20; i++) {
  83:              WoTou wt = ss.pop();
  84:  System.out.println("消费了: " + wt);
  85:              try {
  86:                  Thread.sleep((int)(Math.random() * 1000));
  87:              } catch (InterruptedException e) {
  88:                  e.printStackTrace();
  89:              }
  90:          }
  91:      }
  92:  }

:smile: 表情测试~

图片/代码/emoji

转载于:https://my.oschina.net/alexzed/blog/150372

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值