黑马程序员技术交流社区
标题:
一个关于多线程的问题
[打印本页]
作者:
贾浩田
时间:
2014-8-26 18:54
标题:
一个关于多线程的问题
class Ticket1 implements Runnable{
private String name;
private int ticket = 50;
public Ticket1(String name){
this.name = name;
}
@Override
public void run() {
// TODO Auto-generated method stub
for(int i = 0; i<this.ticket; i++ ){
synchronized(this){
System.out.println(this.name+Thread.currentThread().getName()+"--->"+i);
}
}
}
}
public class test {
public static void main(String[] args) {
Ticket1 t1 = new Ticket1("实现方式");
new Thread(t1).start();
new Thread(t1).start();
new Thread(t1).start();
}
}
这是一个很简单的例子啊,我和我没有达到共享车票的目的
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2