diff --git a/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java b/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java --- a/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java +++ b/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java @@ -100,6 +100,11 @@ /** maxsize for passing ByteArrayInputStream*/ private static final long MEM_STREAM_SIZE = 100000; + /** Maximal time for which closing of jar is postponed. */ + private static final int CLOSE_DELAY_MAX = 5000; + /** Mininal time for which closing of jar is postponed. */ + private static final int CLOSE_DELAY_MIN = 300; + /** * Opened zip file of this filesystem is stored here or null. */ @@ -138,6 +143,11 @@ private transient FileObject foRoot; private transient FileChangeListener fcl; + /** Actual time for which closing of jar is postponed. */ + private transient int closeDelay = CLOSE_DELAY_MIN; + /** Time of request for opening of jar. */ + private transient long openRequestTime = 0; + /** * Default constructor. *

Most module code should never create an instance of this class directly. @@ -282,6 +292,7 @@ closeCurrentRoot(false); jar = tempJar; + openRequestTime = System.currentTimeMillis(); root = new File(s); if (refreshRoot) { @@ -671,6 +682,13 @@ closeTask.cancel(); } + // #167527 - calculate adaptive delay before closing jar + long now = System.currentTimeMillis(); + long requestPeriod = now - openRequestTime; + openRequestTime = now; + // 150% of time from last open request, but between CLOSE_DELAY_MIN and CLOSE_DELAY_MAX + closeDelay = (int) Math.min(CLOSE_DELAY_MAX, Math.max(CLOSE_DELAY_MIN, (1.5 * requestPeriod))); + JarFile j = jar; if (j != null) { @@ -698,7 +716,7 @@ if (isRealClose) { realClose().run(); } else { - closeTask = req.post(realClose(), 300); + closeTask = req.post(realClose(), closeDelay); } } }