net.sf.ehcache.util.UpdateChecker
解决问题:
net.sf.ehcache.util.UpdateChecker:98] New update(s) found: 2.4.7 [http://www.terracotta.org/confluence/display/release/Release+Notes+Ehcache+Core+2.4]. Please check http://ehcache.org for the latest version.
因为项目用到了ehcache,所以tomcat每次启动日志就打印net.sf.ehcache.util.UpdateChecker doCheck
以前也没有特别留意,今天在启动 Tomcat 的时候,发现了下面这段输出的信息:
2014-11-12 11:00:11 [INFO ] [net.sf.ehcache.util.UpdateChecker:98] New update(s) found: 2.4.7 [http://www.terracotta.org/confluence/display/release/Release+Notes+Ehcache+Core+2.4]. Please check http://ehcache.org for the latest version
分析才知道,EhCache在每次启动的时候都要连接到 ehcache 网站上去检查新版本,所以谁在用
ehcache,他们可是一目了然啊。
解决问题,修改配置,关闭更新检测:
打开 ehcache.xml 将第一行 <ehcache> 的属性 updateCheck 改为false,如下:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false">
源码:
public class UpdateChecker extends TimerTask { private static final Logger LOG = LoggerFactory.getLogger(UpdateChecker.class.getName()); private static final long MILLIS_PER_SECOND = 1000L; private static final int CONNECT_TIMEOUT = 3000; private static final String NOT_AVAILABLE = "UNKNOWN"; private static final String UPDATE_CHECK_URL = "http://www.terracotta.org/kit/reflector?kitID=ehcache.default&pageID=update.properties"; private static final long START_TIME = System.currentTimeMillis(); public void run() { checkForUpdate(); } public void checkForUpdate() { try { if (!(Boolean.getBoolean("net.sf.ehcache.skipUpdateCheck"))) doCheck(); } catch (Throwable t) { LOG.debug("Update check failed: " + t.toString()); } } private void doCheck() throws IOException { LOG.debug("Checking for update..."); URL updateUrl = buildUpdateCheckUrl(); Properties updateProps = getUpdateProperties(updateUrl); String currentVersion = new ProductInfo().getVersion(); String propVal = updateProps.getProperty("general.notice"); if (notBlank(propVal)) LOG.info(propVal); propVal = updateProps.getProperty(currentVersion + ".notice"); if (notBlank(propVal)) LOG.info(propVal); propVal = updateProps.getProperty(currentVersion + ".updates"); if (notBlank(propVal)) { StringBuilder sb = new StringBuilder(); String[] newVersions = propVal.split(","); for (int i = 0; i < newVersions.length; ++i) { String newVersion = newVersions[i].trim(); if (i > 0) sb.append(", "); sb.append(newVersion); propVal = updateProps.getProperty(newVersion + ".release-notes"); if (notBlank(propVal)) { sb.append(" ["); sb.append(propVal); sb.append("]"); } } if (sb.length() > 0) LOG.info("New update(s) found: " + sb.toString() + ". Please check http://ehcache.org for the latest version."); } } private Properties getUpdateProperties(URL updateUrl) throws IOException { URLConnection connection = updateUrl.openConnection(); connection.setConnectTimeout(3000); InputStream in = connection.getInputStream(); try { Properties props = new Properties(); props.load(connection.getInputStream()); Properties localProperties1 = props; return localProperties1; } finally { if (in != null) in.close(); } } private URL buildUpdateCheckUrl() throws MalformedURLException, UnsupportedEncodingException { String url = System.getProperty("ehcache.update-check.url", "http://www.terracotta.org/kit/reflector?kitID=ehcache.default&pageID=update.properties"); String connector = (url.indexOf(63) > 0) ? "&" : "?"; return new URL(url + connector + buildParamsString()); } private String buildParamsString() throws UnsupportedEncodingException { ProductInfo productInfo = new ProductInfo(); StringBuilder sb = new StringBuilder(); sb.append("id="); sb.append(getClientId()); sb.append("&os-name="); sb.append(urlEncode(getProperty("os.name"))); sb.append("&jvm-name="); sb.append(urlEncode(getProperty("java.vm.name"))); sb.append("&jvm-version="); sb.append(urlEncode(getProperty("java.version"))); sb.append("&platform="); sb.append(urlEncode(getProperty("os.arch"))); sb.append("&tc-version="); sb.append("UNKNOWN"); sb.append("&tc-product="); sb.append(urlEncode(productInfo.getName() + " " + productInfo.getVersion())); sb.append("&source="); sb.append(urlEncode(productInfo.getName())); sb.append("&uptime-secs="); sb.append(getUptimeInSeconds()); sb.append("&patch="); sb.append(urlEncode(productInfo.getPatchLevel())); return sb.toString(); } private long getUptimeInSeconds() { long uptime = System.currentTimeMillis() - START_TIME; return ((uptime > -5761795191333715968L) ? uptime / 1000L : -5761795156973977600L); } private int getClientId() { try { return InetAddress.getLocalHost().hashCode(); } catch (Throwable t) { } return 0; } private String urlEncode(String param) throws UnsupportedEncodingException { return URLEncoder.encode(param, "UTF-8"); } private String getProperty(String prop) { return System.getProperty(prop, "UNKNOWN"); } private boolean notBlank(String s) { return ((s != null) && (s.trim().length() > 0)); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。