Jacob. dll already loaded in another classloader

Source: Internet
Author: User

 

Unsatisfiedlinkerror occurs when Jacob is used. [original]

Problem description:
I use Jacob in a web application (the server is a resin-ee-2.1.4) to automate the conversion of Word documents to PDF documents (see my other log), in order to ensure the stability of Web applications, I provide the auto-Restart mechanism for resin every night by modifying the resin by using the scheduled servlet. CONF file. However, when the web application restarts, Jacob reports the following error;
Native library C:/winnt/system32/Jacob. dll already loaded in another classloader
Java. Lang. unsatisfiedlinkerror: Native library C:/winnt/system32/Jacob. dll already loaded in another classloader
At java. Lang. classloader. loadlibrary0 (classloader. Java: 1437)
At java. Lang. classloader. loadlibrary (classloader. Java: 1397)
At java. Lang. runtime. loadlibrary0 (runtime. Java: 788)
At java. Lang. system. loadlibrary (system. Java: 832)
At com.jacb.com. variant. <clinit> (variant. Java)
......
Then, the function of converting to PDF will be permanently invalid until the resin service is manually restarted.

Problem Analysis:
View JacobSource codeIt is found that there is a static method in the variant class:
Static {
System. loadlibrary ("Jacob ";
}
The unsatisfiedlinkerror error indicates that Jacob. dll has been loaded by the JVM classloader. We found that the automatic restart mechanism of Web server is the root cause of this problem. When resin restarts the web application containing Jacob, it will automatically execute Jacob loading because of the variant statements. However, restarting the web application does not restart the entire resin (that is, the last startup JVM still exists). That is to say, Jacob has been loaded, so the system will throw an unsatisfiedlinkerror error. When resin is manually restarted, the last started JVM is shut down and restarted, and Jacob is loaded normally.

Solution:
Java API indicates that JVM only allows one default classloader to load native library, and does not provide a special API to unload a loaded native library. Therefore, we cannot restart the Web ApplicationCodeTo manually clear the loaded Jacob. Therefore, we must ensure that Jacob is not repeatedly loaded when the web application is restarted. put the jar package in the public lib folder of the Web server (for example :... /resin-ee-2.1.4/lib/), instead of the Web application lib (such :... /WEB-INF/lib /). After testing, after the web application is automatically restarted, the problem no longer occurs.

Postscript:
although the problem has been solved, it is always uncomfortable. After all, it is not solved from the root cause. Users who want to see this log will continue their research. If they can find out the unload loaded native library method, they hope to share it with everyone.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.