码迷,mamicode.com
首页 > 编程语言 > 详细

java多线程

时间:2017-10-31 23:48:07      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:thread   ring   art   main   tar   sum   str   int   highlight   

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多线程

标签:thread   ring   art   main   tar   sum   str   int   highlight   

原文地址:http://www.cnblogs.com/mathyk/p/7764333.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!