首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java 线程共享有关问题

2012-10-11 
java线程共享问题package thread/** * 实现Runnable 可资源共享 * @author lixunhui */public class MyTh

java 线程共享问题

package thread;/** * 实现Runnable 可资源共享 * @author lixunhui */public class MyThread5 implements Runnable { private int ticket=5; @Override public synchronized void run() {  for(int i=0;i<100;i++){   if(ticket>0){    try {     Thread.sleep(1000);    } catch (InterruptedException e) {     e.printStackTrace();    }    System.out.println("Bye ticket.."+ticket--);   }  } } public static void main(String[] args) {  MyThread5 thread=new MyThread5();  Thread t1=new Thread(thread);  Thread t2=new Thread(thread);  t1.start();  t2.start(); }}

?

热点排行