inner class与重载问题

今天貌似发现了一个java的bug.
这是一个内部匿名类调用外部类方法的问题.
我在外部类中有个notifyAll(Object me)方法,在内部匿名类里却无法调用它,编译报错。
尝试把notifyAll改名为tellAll,——恩,蛮好,可以调用。
尝试写成 OuterClassName.this.notifyAll(me)——恩,也可以调用。
看起来如果在外部类中重载Object的方法,java无法区分。

ExpandedBlockStart.gif ContractedBlock.gif /** */ /**
InBlock.gif * 
ExpandedBlockEnd.gif 
*/

None.gif
package  cn.roob.webdown.statistic;
None.gif
None.gif
import  java.util.concurrent.Executors;
None.gif
import  java.util.concurrent.ScheduledExecutorService;
None.gif
import  java.util.concurrent.TimeUnit;
None.gif
None.gif
import  org.apache.log4j.Logger;
None.gif
None.gif
import  cn.roob.webdown.persist.StatisticDAO;
None.gif
import  cn.roob.webdown.persist.TaskCountRecord;
None.gif
import  cn.roob.webdown.util.Config;
None.gif
ExpandedBlockStart.gifContractedBlock.gif
/** */ /**
InBlock.gif * 任务状态定时统计线程,只记录发生了变动的统计结果.<br>
InBlock.gif * 以单例模式运行,通过观察者模式发送统计结果<br>
InBlock.gif * 典型的观察者有客户端通讯和统计曲线图
InBlock.gif * 
InBlock.gif * 
@author  tedeyang
InBlock.gif * 
ExpandedBlockEnd.gif 
*/

ExpandedBlockStart.gifContractedBlock.gif
public   class  TaskStatistic  extends  CommonStatisticSource  dot.gif {
InBlock.gif    
static   private   int  statisticRate  =  Config.getApplicationConfig().statisticRate();
InBlock.gif    
static   private  TaskStatistic thread  =   null ;
InBlock.gif    
private   static  Logger log  =  Logger.getLogger(TaskStatistic. class );
InBlock.gif    
private   final  ScheduledExecutorService schedule  =  Executors.newSingleThreadScheduledExecutor();
InBlock.gif    
private   boolean  started  =   false ;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
private  TaskStatistic()  dot.gif {
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public   static  TaskStatistic getSingleScheduledThread()  dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if  (thread  ==   null dot.gif {
InBlock.gif            thread 
=   new  TaskStatistic();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
return  thread;
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/** */ /**
InBlock.gif     * 在垃圾收集前停止线程
InBlock.gif     * 
@see  java.lang.Object#finalize()
ExpandedSubBlockEnd.gif     
*/

ExpandedSubBlockStart.gifContractedSubBlock.gif    
protected   void  finalize()  throws  Throwable  dot.gif {
InBlock.gif        
this .stop();
InBlock.gif        
super .finalize();
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/** */ /**
InBlock.gif     * 启动,以固定的延迟频率统计数据库中任务的状态,如果状态发生变化则通知监听者,并记录.
ExpandedSubBlockEnd.gif     
*/

ExpandedSubBlockStart.gifContractedSubBlock.gif    
public   void  start()  dot.gif {
InBlock.gif        
if  (started)
InBlock.gif            
return ;
InBlock.gif        
if  (log.isInfoEnabled())
InBlock.gif            log.info(
" 启动任务统计线程 " );
InBlock.gif        started 
=   true ;
InBlock.gif
InBlock.gif        
final  StatisticDAO dao  =   new  StatisticDAO();
InBlock.gif        schedule.scheduleWithFixedDelay(
InBlock.gif                
ExpandedSubBlockStart.gifContractedSubBlock.gif                
new  Runnable()  dot.gif {
InBlock.gif                    TaskCountRecord lastRecord 
=   null ;
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
public   void  run()  dot.gif {
InBlock.gif                        TaskCountRecord totalCount 
=  dao.countTaskStatus();
InBlock.gif                        
//  任务数没有变化则不更新
ExpandedSubBlockStart.gifContractedSubBlock.gif
                         if  ( ! totalCount.equals(lastRecord))  dot.gif {
InBlock.gif                            lastRecord 
=  totalCount;
InBlock.gif                            tellAllObservers(totalCount);
InBlock.gif                            dao.save(totalCount); 
                                notifyAll(totalCount);//该方法在父类中
ExpandedSubBlockEnd.gif                        }
 
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }
,
InBlock.gif                statisticRate, 
InBlock.gif                statisticRate, 
InBlock.gif                TimeUnit.SECONDS
InBlock.gif        );
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/** */ /**
InBlock.gif     * 结束
ExpandedSubBlockEnd.gif     
*/

ExpandedSubBlockStart.gifContractedSubBlock.gif    
public   void  stop()  dot.gif {
InBlock.gif        schedule.shutdown();
InBlock.gif        started 
=   false ;
InBlock.gif        
if  (log.isInfoEnabled())
InBlock.gif            log.info(
" 停止任务统计线程 " );
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值