其中StorefrontMemoryDatabasePlugIn这个l类中有这么一段代码:
IStorefrontServiceFactory factory = null;try {
factory = StorefrontServiceFactory.getInstance();
} catch (Exception ex) {
throw new ServletException(ex.getMessage());
}IStorefrontServiceFactory是一个接口;
public interface IStorefrontServiceFactory {
public IStorefrontService createService()
throws ClassNotFoundException, IllegalAccessException, InstantiationException;
}
然后StorefrontServiceFactory这个类是这样的:
public class StorefrontServiceFactory implements IStorefrontServiceFactory { // The default is to use the debug implementation
private static String serviceClassname =
"com.oreilly.struts.storefront.service.StorefrontDebugServiceImpl"; private static IStorefrontServiceFactory Singleton = null; public static IStorefrontServiceFactory getInstance() { synchronized (StorefrontServiceFactory.class) {
if (Singleton == null) {
Singleton = new StorefrontServiceFactory();
return Singleton;
}
}
return Singleton;
} private StorefrontServiceFactory() {
init();
} public void init() {
IStorefrontService service = null;
try { service =
(IStorefrontService) Class
.forName(serviceClassname)
.newInstance();
} catch (Exception ex) {
// Swallow the exception and let it occur during the createService() method call.
ex.printStackTrace();
}
} public IStorefrontService createService()
throws
ClassNotFoundException,
IllegalAccessException,
InstantiationException {
return (IStorefrontService) Class
.forName(getServiceClassname())
.newInstance();
} /**
* @return
*/
public static String getServiceClassname() {
return serviceClassname;
} /**
* @param string
*/
public static void setServiceClassname(String string) {
serviceClassname = string;
}
}
我的问题是:从factory = StorefrontServiceFactory.getInstance();开始的程序执行顺序是怎么样的?
IStorefrontServiceFactory factory = null;try {
factory = StorefrontServiceFactory.getInstance();
} catch (Exception ex) {
throw new ServletException(ex.getMessage());
}IStorefrontServiceFactory是一个接口;
public interface IStorefrontServiceFactory {
public IStorefrontService createService()
throws ClassNotFoundException, IllegalAccessException, InstantiationException;
}
然后StorefrontServiceFactory这个类是这样的:
public class StorefrontServiceFactory implements IStorefrontServiceFactory { // The default is to use the debug implementation
private static String serviceClassname =
"com.oreilly.struts.storefront.service.StorefrontDebugServiceImpl"; private static IStorefrontServiceFactory Singleton = null; public static IStorefrontServiceFactory getInstance() { synchronized (StorefrontServiceFactory.class) {
if (Singleton == null) {
Singleton = new StorefrontServiceFactory();
return Singleton;
}
}
return Singleton;
} private StorefrontServiceFactory() {
init();
} public void init() {
IStorefrontService service = null;
try { service =
(IStorefrontService) Class
.forName(serviceClassname)
.newInstance();
} catch (Exception ex) {
// Swallow the exception and let it occur during the createService() method call.
ex.printStackTrace();
}
} public IStorefrontService createService()
throws
ClassNotFoundException,
IllegalAccessException,
InstantiationException {
return (IStorefrontService) Class
.forName(getServiceClassname())
.newInstance();
} /**
* @return
*/
public static String getServiceClassname() {
return serviceClassname;
} /**
* @param string
*/
public static void setServiceClassname(String string) {
serviceClassname = string;
}
}
我的问题是:从factory = StorefrontServiceFactory.getInstance();开始的程序执行顺序是怎么样的?
解决方案 »
- Native中在未传入jobject的方法中调用java方法
- 数组初始化列表最后可选逗号,此特性使维护长列表变得更容易?
- 如何设置输出图片质量
- 请教个关于java的小问题
- while(stopFlag == false) 好 还是 while(!topFlag)
- 怎样把一个src.zip的源码包添加到Eclipse项目中?
- 请教JSP做流量访问系统中的IP显示问题??急~~~~
- Timer类的问题请教,救急!!!各位高手请进!!!
- Jbuilder编的程序控件用到querydataset,编译通过后,ie中为什么出现错误?
- 新人求指导下
- 如何将图片缩小
- JDBC传递参数的问题--SQL的IN关键字
1.getInstance;
2.1如果没有实例化工厂类,则new StorefrontServiceFactory();
2.2调用init
3.如果已实例化了,则直接返回了,不再实例化与init.