问题
1.外部刷新与定时刷新共同进行进会不会有异常
2.存不存在不合理的地方
public class SecurityCache { private static List CMD_URL = new ArrayList(); //缓存数据存放LIST中
private static String VERSION = "1.000"; //版本控制信息
protected static ISecurityService getService() {
return (ISecurityService) PublicCode.
getWebAppContext().
getBean("securityCtrlService"); } private SecurityCache() {
synchronized (this) { }
}
//启动时加载并实现定时刷新
public static synchronized void init() throws SecurityException {
Timer timer = new Timer(true);
timer.schedule(new java.util.TimerTask() {
public void run() {
List cm_url = CMD_URL;
try {
CMD_URL = getService().findMenuInfo();
}
catch (Exception e) {
CMD_URL = cm_url;
}
finally {
cm_url.clear();
cm_url = null;
}
}
} , 0, getService().getInterval() * 60 * 1000); }
//外部应用实现刷新
public static synchronized void refresh() throws SecurityException {
List cm_url = CMD_URL;
try {
CMD_URL = getService().findMenuInfo();
}
catch (Exception e) {
CMD_URL = cm_url;
}
finally {
cm_url.clear();
cm_url = null;
} } public static void destroy() throws SecurityException {
CMD_URL.clear();
CMD_URL = null;
VERSION = null;
} public static List getCMD_URL() {
return CMD_URL;
} public static String getVERSION() {
return VERSION;
}
}
1.外部刷新与定时刷新共同进行进会不会有异常
2.存不存在不合理的地方
public class SecurityCache { private static List CMD_URL = new ArrayList(); //缓存数据存放LIST中
private static String VERSION = "1.000"; //版本控制信息
protected static ISecurityService getService() {
return (ISecurityService) PublicCode.
getWebAppContext().
getBean("securityCtrlService"); } private SecurityCache() {
synchronized (this) { }
}
//启动时加载并实现定时刷新
public static synchronized void init() throws SecurityException {
Timer timer = new Timer(true);
timer.schedule(new java.util.TimerTask() {
public void run() {
List cm_url = CMD_URL;
try {
CMD_URL = getService().findMenuInfo();
}
catch (Exception e) {
CMD_URL = cm_url;
}
finally {
cm_url.clear();
cm_url = null;
}
}
} , 0, getService().getInterval() * 60 * 1000); }
//外部应用实现刷新
public static synchronized void refresh() throws SecurityException {
List cm_url = CMD_URL;
try {
CMD_URL = getService().findMenuInfo();
}
catch (Exception e) {
CMD_URL = cm_url;
}
finally {
cm_url.clear();
cm_url = null;
} } public static void destroy() throws SecurityException {
CMD_URL.clear();
CMD_URL = null;
VERSION = null;
} public static List getCMD_URL() {
return CMD_URL;
} public static String getVERSION() {
return VERSION;
}
}
TimerTask的run方法没有同步。
private static List CMD_URL = new ArrayList()
最好为
private static List CMD_URL = Collections.synchronizedList(new ArrayList());