So far, I've encountered three cases of using Tomcat: first, using Eclipse to configure Tomcat in Eclipse. Second, deploy the project directly in Tomcat. The third is to install Tomcat as a Windows service.
In these three cases, the emergence of outofmemoryerror. How to solve it? Here I have to mention that I was badly hurt by the irresponsible articles on the Internet. Various methods of setting up memory have been tried, but it just doesn't work. I have tried these methods myself, no problem.
In the first case:
As pictured: I came out of the red box. where XMS and xmx is to increase the Java Virtual machine initial heap size and maximum heap size parameters, mainly to solve the Java Heap due to the lack of space cause. Xx:permsize and xx:maxpermsize are parameters that increase the initial permanent save area size and maximum permanent save area size, and the main solution uses a large number of jars or class,java virtual machine load classes that are not enough space, with permanent Generation space related.
In the second case:
put the compiled project directly into Tomcat, using Startup.bat to start the Tomcat service. The following are under the Tomca Bin folder:
In this case, we want to modify the parameters inside the Catalina.bat. Open it. Find these two sentences:
rem Guess catalina_home if not defined
Set "current_dir=%cd%"
Add this sentence above these two sentences, it must be above: Set "java_opts=-xms512m-xmx1024m-xx:permsize=256m-xx:maxpermsize=512m"
A lot of similar on the internet, but try a lot of no, be sure to note: its position, and quotes and other details.
In the third case:
If your tomcat is registered as a Windows service and is started as a service, the above method is invalid because Tomcat startup is reading the parameters of the registry instead of reading the parameters of the batch file, so we set the JVM parameters. : Find Tomcat7w.exe in Tomcat's Bin directory, open:
Under the Java option: The initial memory pool is the initialization heap memory size, maximun memory pool is the maximum heap memory size. To set the size of the Perm Gen pool, you add parameters to the Java option, plus:
-dcatalina.base=%tomcat_home%
-dcatalina.home=%tomcat_home%
-djava.endorsed.dirs=%tomcat_home%\endorsed
-djava.io.tmpdir=%tomcat_home%\temp
-xx:permsize=256m
-xx:maxpermsize=256m
-xx:reservedcodecachesize=48m
-duser.timezone=gmt+08
(Do not have spaces after each line) This method I tried, it worked. You can also add parameters directly to the registry. This is not introduced, I have not tried.
In fact, it is not difficult to solve the problem of Tomcat memory, it is rare how you know this is due to the Tomcat memory overflow exception. We've had a long time on this issue before. If you print out an error message in the Eclipse,console, you can directly determine if it is outofmemoryerror, and if you are deploying directly to Tomcat to start Startup.bat, you can also see the printed error message. But instead of installing the Tomcat service as a Windows service, we don't see any false hints. After the project started, has been in the waiting state, very slow and slow, so that people do not feel the mind, is catching up with the database also strike, has been thought to be a database problem. In a word: lack of experience.
The above is about solving all the contents of OutOfMemoryError in Java, I hope to help you learn.