本帖最后由 刘文飞 于 2012-11-16 18:52 编辑
- class Ticket implements Runnable
- {
- private static int tick = 100;
- boolean flag = true;
- public void run(){
- if(flag)
- {
- while(true)
- {
- synchronized(this)
- {
- if(tick>0)
- {
- try{Thread.sleep(10);}catch(InterruptedException e){e.printStackTrace();}
- System.out.println("======code=====" + Thread.currentThread().getName() + tick--);
- }
- }
- }
- }
- else
- {
- while(true)
- {
- show();
- }
- }
- }
- private synchronized void show()
- {
- if(tick>0)
- {
- try{Thread.sleep(10);}catch(InterruptedException e){e.printStackTrace();}
- System.out.println("======show=====" + Thread.currentThread().getName() + tick--);
- }
- }
- }
- public class StaticMethodDemoMe
- {
- public static void main(String args[])
- {
- Runnable run = new Ticket();
- Thread t1 = new Thread(run);
- Thread t2 = new Thread(run);
- t1.start();
- try{Thread.sleep(10);}catch(Exception e){}
- run.flag = false;//找不到符号
- t2.start();
- }
- }
复制代码 G:\hezi\Code>javac StaticMethodDemoMe.java
StaticMethodDemoMe.java:46: 错误: 找不到符号
run.flag = false;//找不到符号
^
符号: 变量 flag
位置: 类型为Runnable的变量 run
1 个错误
|