java多线程
Posted yacbo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java多线程相关的知识,希望对你有一定的参考价值。
public static void main() { Resource r = new Resource(); Producer pro = new Producer(r); Consumer con = new Consumer(r); Thread t1 = new Thread(pro); Thread t2= new Thread(con); t1.start(); t2.start(); } class Resource { private String name; private int count = 1; private bolean flag = flag; public synchroized void set(String name) { } public synchroized void out() { } } class Producer implements Runnable { private Resource res; Producer(Resource res) { this.res = res; } public void run() { while(true) { res.set("shangpin"); } } } class Consumer implements Runnable { private Resource res; Producer(Resource res) { this.res = res; } public void run() { while(true) { res.out(); } } }
以上是关于java多线程的主要内容,如果未能解决你的问题,请参考以下文章