class Sample{
    private static mySample = null;
    private Sample(){
        you init    
    }
    public static Sample getInstance(){
       if( this.mySample == null ){
           this.mySample = new Sample();
       }
       ruturn this.mySample;
    }
}class anotherclass{
    Sample hehe = Sample.getInstance();
}

解决方案 »

  1.   

    这个方法我觉得不行,因为100个servlet调用的是100个anotherclass的实例,所以得到的是100个不同的Sample
      

  2.   

    ft虽让你调anotherclass的实例的anotherclass就是你的servlet  Sample就是你要调用的那个类!!!。可能没写明白,ft.class Sample{
        private static mySample = null;
        private Sample(){
            you init    
        }
        public static Sample getInstance(){
           if( this.mySample == null ){
               this.mySample = new Sample();
           }
           ruturn this.mySample;
        }
    }class yourserverlet{
        Sample hehe = Sample.getInstance();
    }