Before the company project has been running on the Tomcat6, a few days before the request for TOMCAT7, the result unexpectedly appeared a series of errors, the following summarizes the difference between TOMCAT6 and TOMCAT7:
The first one:
is about database driver loading. A database-driven anomaly, Tomcat7. Because Tomcat restricts the execution of static code when the class loads execute, it needs to be able to actually execute when the object is generated, so the database driver is familiar with the way it was loaded before TOMCAT6:
1 |
Class<?> cls = com.mysql.jdbc.Driver. class ; |
3 |
Class.forName( "com.mysql.jdbc.Driver" ); |
The "No suitable driver found for JDBC" exception occurs when a database connection is generated using DriverManager.
Now the correct way to load the database driver requires that the object of the database driver class be generated. Recommended
1 |
com.mysql.jdbc.Driver. class .newInstance(); |
This method does not handle exceptions, and the resulting useless objects are garbage collected for the shortest time.
Among them, Java.sql.Driver is the interface of the driver class provided by each database management system, which belongs to the JDBC specification and is suitable for import java.sql.Driver; Be abbreviated.
The second one:
is a thread-initiated issue. Because of the TOMCAT7 or-server way of running JV) Some of the protection mechanisms I have not mastered, so when a thread goes through an empty loop, it will be overhead.
So through the flag as a control method of the thread control variables, there is no way to continue to use. At this point, you should always skip this manually-jammed thread so that it can always be executed without really getting stuck.
1 |
while (flag) { Thread.yield(); } |
tomcat7 Configuration file, the Context configuration, the Debug attribute is canceled, and if it is still used, a warning is reported.
third:
05 |
docBase= "/usr/local/example.war" |
crosscontext="true" is to allow the app to get a request to another application via Servletcontext.getcontext () dispatcher. Of course, this approach does not span the virtual host boundaries currently supported by Tomcat. In other words, the ability to penetrate access must be and is currently applied in a <Host> application.
privileged="true" means the application of Tomcat itself, such as · Tomcat Manager, which can be accessed by the current application. According to the official documentation, the mechanism is to change the application of the ClassLoader to the Server class loader. I think this change will enable the application to discover the classes of Tomcat itself, all of which can be found from the application's own ClassLoader. This enables calls to Tomcat's own application methods.
path and docBase do not have to say more, you have to specify the two attributes. Where docBase can be a directory or a fully structured. War file.
reloadable="true" means that Tomcat will provide monitoring of the application Classpath (/web-inf/classes/and/web-inf/lib/). Tomcat can reload the class itself when there is a change in the content and its class has been loaded by the Java Virtual Machine (JVM). However, this feature has a small impact on Tomcat's stable service, debugging environment can be used, production environment or not--of course, this is just my personal advice.
Unpackwar is literally, unpackwar= "true" means that Tomcat will save the extracted results of the war package, and then run the decompression results directly. I personally think that, considering the Java Virtual machine class loading mechanism, each class is loaded only once, but the page content does not have a similar valid cache, so the. War or decompression execution is better. And the log will also cause unpackwar= "false" with disaster.
cachingallowed="true" means that the TOMCAT7 static caching feature is turned on. Static files include JavaScript programs, picture sounds, and other files that allow network access, as well as HTML pages.
cachemaxsize is the setting of the buffer size for the static cache function. The unit is MB, which is 1024KB. The example is set to 1024, which means 1GB.
Fourth One:
TOMCAT6 Configuring Administrator Information
1: Open the ~/conf/tomcat-users.xml file under Tomcat6, the information about the user role and the administrator is in this configuration file.
2: Add the following XML under Config file <tomcat-users> node
<role rolename= "admin"/>
<role rolename= "manager"/>
<user username= "admin" password= "admin" roles= "Admin,manager"/>
3: Start Tomat6, enter: Username: admin Password: admin login to admin interface.
TOMCAT7 Configuring Administrator Information
1: Open the ~/conf/tomcat-users.xml file under TOMCAT7, the information about the user role and the administrator is in this configuration file.
2: Add the following XML under Config file <tomcat-users> node
<role rolename= "Admin-gui"/>
<role rolename= "Manager-gui"/>
<user username= "admin" password= "admin" roles= " Admin-gui , manager-gui "/>
3: Start TOMAT7, enter: Username: admin Password: admin login to admin interface.
Tomcat7 Introduction (i)