浏览 2279 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2006-09-07
windows2003 配置文件: class NewThread implements Runnable { String name; Thread t; boolean suspendFlag; NewThread(String threadname){ name=threadname; t=new Thread(this,name); while(name=="one"){ t.setPriority(Thread.NORM_PRIORITY+2); }; System.out.println("New thread:"+t); suspendFlag=false; t.start(); } public void run(){ try{ for(int i=15;i>0;i--){ System.out.println(name+":"+i); Thread.sleep(200); synchronized(this){ while(suspendFlag){ wait(); } } } }catch(InterruptedException e){ System.out.println(name+"interrupted."); } System.out.println(name+"exiting."); } void mysuspend(){ suspendFlag=true; } synchronized void myresume(){ suspendFlag=false; notify(); } }; class SuspendResume { public static void main(String args[]){ NewThread ob1=new NewThread("one"); NewThread ob2=new NewThread("two"); try{ Thread.sleep(1000); ob1.mysuspend(); System.out.println("Suspending thread One"); Thread.sleep(1000); ob1.myresume(); System.out.println("Resuming thread One"); ob2.mysuspend(); System.out.println("Suspending thread Two"); Thread.sleep(1000); ob2.myresume(); System.out.println("Resuming thread Two"); }catch(InterruptedException e){ System.out.println("Main thread Interrupted"); } try{ System.out.println("Waiting for threads to finish."); ob1.t.join(); ob2.t.join(); }catch(InterruptedException e){ System.out.println("Main thread Interrupted"); } System.out.println("Main thread exiting."); } }; 本来是为了测试高优先级线程运行情况,就加了这条语句(本来是没有下面这条语句的,而且还能运行) while(name=="one"){ t.setPriority(Thread.NORM_PRIORITY+2); }; 当我加了这条测试语句的时候,文件连编译都成问题了,请教。。。 错误提示信息: CMD下面编译不出来 2次编译后 又编译出来了 但是解析下 发现 只有光标不停的闪烁 不能输出字符 你的分析: 不太明白到底是怎么回事,我想不可能是死琐啊 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |