src/solaris/classes/sun/net/www/protocol/jar/JarFileFactory.java
Print this page
*** 41,57 ****
* @since JDK1.2
*/
class JarFileFactory implements URLJarFile.URLJarFileCloseController {
/* the url to file cache */
! private static HashMap<String, JarFile> fileCache = new HashMap<String, JarFile>();
/* the file to url cache */
! private static HashMap<JarFile, URL> urlCache = new HashMap<JarFile, URL>();
URLConnection getConnection(JarFile jarFile) throws IOException {
! URL u = urlCache.get(jarFile);
if (u != null)
return u.openConnection();
return null;
}
--- 41,68 ----
* @since JDK1.2
*/
class JarFileFactory implements URLJarFile.URLJarFileCloseController {
/* the url to file cache */
! private static final HashMap<String, JarFile> fileCache = new HashMap<>();
/* the file to url cache */
! private static final HashMap<JarFile, URL> urlCache = new HashMap<>();
+ private static final JarFileFactory instance = new JarFileFactory();
+
+ private JarFileFactory() { }
+
+ public static JarFileFactory getInstance() {
+ return instance;
+ }
+
URLConnection getConnection(JarFile jarFile) throws IOException {
! URL u;
! synchronized (instance) {
! u = urlCache.get(jarFile);
! }
if (u != null)
return u.openConnection();
return null;
}
*** 60,79 ****
return get(url, true);
}
JarFile get(URL url, boolean useCaches) throws IOException {
! JarFile result = null;
! JarFile local_result = null;
if (useCaches) {
! synchronized (this) {
result = getCachedJarFile(url);
}
if (result == null) {
local_result = URLJarFile.getJarFile(url, this);
! synchronized (this) {
result = getCachedJarFile(url);
if (result == null) {
fileCache.put(URLUtil.urlNoFragString(url), local_result);
urlCache.put(local_result, url);
result = local_result;
--- 71,90 ----
return get(url, true);
}
JarFile get(URL url, boolean useCaches) throws IOException {
! JarFile result;
! JarFile local_result;
if (useCaches) {
! synchronized (instance) {
result = getCachedJarFile(url);
}
if (result == null) {
local_result = URLJarFile.getJarFile(url, this);
! synchronized (instance) {
result = getCachedJarFile(url);
if (result == null) {
fileCache.put(URLUtil.urlNoFragString(url), local_result);
urlCache.put(local_result, url);
result = local_result;
*** 97,113 ****
* Callback method of the URLJarFileCloseController to
* indicate that the JarFile is close. This way we can
* remove the JarFile from the cache
*/
public void close(JarFile jarFile) {
URL urlRemoved = urlCache.remove(jarFile);
! if( urlRemoved != null) {
fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
}
}
!
private JarFile getCachedJarFile(URL url) {
JarFile result = fileCache.get(URLUtil.urlNoFragString(url));
/* if the JAR file is cached, the permission will always be there */
if (result != null) {
--- 108,125 ----
* Callback method of the URLJarFileCloseController to
* indicate that the JarFile is close. This way we can
* remove the JarFile from the cache
*/
public void close(JarFile jarFile) {
+ synchronized (instance) {
URL urlRemoved = urlCache.remove(jarFile);
! if( urlRemoved != null)
fileCache.remove(URLUtil.urlNoFragString(urlRemoved));
}
}
! // must be called while holding the 'instance' lock
private JarFile getCachedJarFile(URL url) {
JarFile result = fileCache.get(URLUtil.urlNoFragString(url));
/* if the JAR file is cached, the permission will always be there */
if (result != null) {