Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating of Spring beans takes a long time when the application is deployed through webstart / jnlp with Java 6 and above [SPR-9117] #13755

Closed
spring-projects-issues opened this issue Feb 13, 2012 · 12 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 13, 2012

Tom Jahncke opened SPR-9117 and commented

Creating an instance of a Spring bean takes a long time when the application is deployed via webstart and the client of application is accessing the application over the WAN.

If a client of the application is remote, creating a bean can take up to 6 seconds. Between the following two lines 6 seconds of time elapse.
CachedIntrospectionResults | Getting BeanInfo for class [com.gfs.wms.service.vendor.buyer.dao.impl.JdbcBuyerDao]
CachedIntrospectionResults | Caching PropertyDescriptors for class [com.gfs.wms.service.vendor.buyer.dao.impl.JdbcBuyerDao]

If I drop the network connection while the beans are being created they are created quickly (few ms) and no exception is thrown ...

I was puzzled by this until ... I realized webstart caching of resources changed between Java 5 and Java 6

Java 6 and Java 7
DefaultBeanDefinitionDocumentReader | Loading bean definitions
PathMatchingResourcePatternResolver | Looking for matching resources in jar file [http://wmstst. ...

Java 5
DefaultBeanDefinitionDocumentReader | Loading bean definitions
PathMatchingResourcePatternResolver | Looking for matching resources in jar file [file:C:/Users/tjahncke/AppData/LocalLow/Sun/Java/Deployment/cache/javaws/http/Dwmstst.gfs.com/P8000/VworkflowManager-10.0.0.0.rc1.jar/DMdc9/DMwms/RMworkflowManager-10.0.0.0.rc1.jar]

It seems that Spring is looking for the jars on the remote site rather than the local cached copy.

Any assistance on having Spring look at the local cached copy instead of the remote jars would be very appreciated!

Thanks,

Tom


Issue Links:

Referenced from: commits fe57f74, 6fd476e

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 13, 2012

Tom Jahncke commented

This issue would probably be resolved if improvement, #13653, is implemented.

This issue is somewhat similar to: #11146

@spring-projects-issues
Copy link
Collaborator Author

Tom Jahncke commented

Here is a summary of the caching changes in Java 6 for webstart:

From, http://www.roseindia.net/java/jdk6/java-web-start.shtml:

JNLP is now an instance of the URLClassLoader - It gives some powerful advantages. First, Jar indexing is now fully supported. If you want to create a jar index of several jar file in the main jar file that indexes all the jar files, and then you can mark each additional jar as lazy, and it can be download only when a resource or class in it is referenced. Second, The JNLPClassLoader was rewritten to extend URLClassLoader. For getting a list of jar elements that are listed in the jnlp files an application can invoke getURLs(). The URL returned for calls to Class Loader.getResource() is proper Jar URL of the item on the net. By extending URLClassLoader, it allows Java Web Start to operate without caching.

@spring-projects-issues
Copy link
Collaborator Author

Tom Jahncke commented

Looking at PathMatchingResourcePatternResolver this may be able to be resolved by allowing the jarCon.useCaches(true) when the con is an instance of JNLPCachedJarURLConnection.


		if (con instanceof JarURLConnection) {
			// Should usually be the case for traditional JAR files.
			JarURLConnection jarCon = (JarURLConnection) con;
			jarCon.setUseCaches(false);
			jarFile = jarCon.getJarFile();
			jarFileUrl = jarCon.getJarFileURL().toExternalForm();
			JarEntry jarEntry = jarCon.getJarEntry();
			rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
		}

@spring-projects-issues
Copy link
Collaborator Author

Tom Jahncke commented

Thank you!

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Seems we have conflicting requirements where for web app hot deploy, we need to deactivate the jar cache whereas for JNLP, we need to keep it activated. Unfortunately, JNLP* are Sun-specific implementation classes so we can probably only reflectively check whether jarCon.getClass().getName().startsWith("JNLP") or the like.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Tom Jahncke commented

Thank you!! Do you know of other places in the spring code base that might refer to JarURLConnection and might have the same issue?

Thanks,

Tom

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good point - I have made sure to use the same useCaches behavior in all places where we obtain a URLConnection.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Tom Jahncke commented

Tested with Spring 3.1.1 and creating the bean still takes a very long time when the resources are sourced from webstart and the network connection is remote.

Excerpt from the log:

2012-02-23 10:27:26:283 | TRACE | AWT-EventQueue-0 | CachedIntrospectionResults | Getting BeanInfo for class [com.gfs.wms.service.vendor.buyer.dao.impl.JdbcBuyerDao]
2012-02-23 10:27:30:392 | TRACE | AWT-EventQueue-0 | CachedIntrospectionResults | Caching PropertyDescriptors for class [com.gfs.wms.service.vendor.buyer.dao.impl.JdbcBuyerDao]

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

Added fixVersion 3.2 M1 just to ensure this reopened issue doesn't get lost in the mix. Juergen can assess from here.

@spring-projects-issues
Copy link
Collaborator Author

Tom Jahncke commented

Thanks!

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This should be fixed since 3.1.3 and also in the 3.2 line.

Juergen

@hamadaExe
Copy link

The same Issue is still happening with me due to external jar when I deploy spring boot(Spring 5.1.9 Framework) on Websphere Liberty .

sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Nov 21, 2023
In order to prevent leaks of large amounts of non-heap
memory (and potential other efficiency and performance side
effects), this commit turns ResourceUtils#useCachesIfNecessary
into a no-op method and deprecates it. It is recommended to
not use it anymore.

This method has been originally introduced via spring-projectsgh-9316 and
spring-projectsgh-13755 to avoid I/O failure during webapp hot reloading in
Servlet containers. This is not a popular deployment mode anymore
and we have not been able to reproduce the original issue with
a Java 17 JVM and Tomcat 10.

Closes spring-projectsgh-30955
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Nov 21, 2023
In order to prevent leaks of large amounts of non-heap
memory (and potential other efficiency and performance side
effects), this commit updates ResourceUtils#useCachesIfNecessary
to leave the caching flag to its JVM default value for instances
of JarURLConnection.

The previous behavior was originally introduced via spring-projectsgh-9316 and
spring-projectsgh-13755 to avoid I/O failure during webapp hot reloading in
Servlet containers. This is not a popular deployment mode anymore
and we have not been able to reproduce the original issue with
a Java 17 JVM and Tomcat 10.

Closes spring-projectsgh-30955
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants