A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 337091921 于 2013-5-12 18:28 编辑

//四个窗口卖票


class Test
{
        public static void main(String args [])
        {
                //tic ti=new tic("线程名字");调用构造函数
                                 tic ti=new tic();
                Thread t=new Thread(ti);
                Thread t1=new Thread(ti);
                Thread t2=new Thread(ti);
                Thread t3=new Thread(ti);
          t.start();        
          t1.start();        
          t2.start();        
          t3.start();        
        
        }
}
class tic implements Runnable
{
                private  int num=100;
                /*private String name;//创建了一个构造函数,想给线程起名子,可惜不可以
                tic(String name)
            {
               
                super();
                }
                */
                public void  run(){
        
        
                while(true){
        
                        if(num>0){
                                System.out.println(Thread.currentThread().getName()+" ======="+num--);
                        }
        
                }
        
        }
}

评分

参与人数 1技术分 +1 收起 理由
曹睿翔 + 1 神马都是浮云

查看全部评分

4 个回复

倒序浏览
起名字可以这样:  Thread t1 = new Thread(t1,"线程一");你可以查查api,看看Thread的构造方法。
回复 使用道具 举报
你的方法应该不可以,tic没有继承Thread,不能调用thread的构造方法
回复 使用道具 举报
楼上已经回答好了,我找点金币...
回复 使用道具 举报
及时更改问题状态,点编辑改为已解决
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马