Arquivo da tag: Tomcat

Tomcat – java.lang.OutOfMemoryError: PermGen space

Apache Tomcat is widely used Web Container in the world. Very big companies run on Apache Tomcat now a days. There are quite a few other alternatives like IBM WebSphere, Geronimo, IIS, etc. but Tomcat is my favorite one too.

It’s very critical for us to configure all correct parameters while running your application in Production environment or even in development env.

In this tutorial we will go over steps on how to configure -Xms, -Xmx and -XX:PermSize value for Tomcat server. Let’s first understand few terms.

-Xmx

Specifies the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or Kto indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. The upper limit for this value will be approximately 4000m on Solaris 7 and Solaris 8 SPARC platforms and 2000m on Solaris 2.6 and x86 platforms, minus overhead amounts. So, in simple words, you are saying Java to use Maximum of 1024 MB from available memory.

NOTE: there is NO SPACE between -Xmx and 1024m

-Xmn

It’s a size of the heap for the young generation.

-XX:PermSize

It’s used to set size for Permanent Generation. It is where class files are kept.

Another must readChange -Xmx value of Tomcat in Eclipse IDE

Let’s get started:

Below are the simple steps to change -Xmx / -Xms values or other JVM parameters if you are running Tomcat from command prompt.

Step-1

Download Apache Tomcat.

Step-2

Go to Apache Tomcat /bin directory.

Create setevn.sh file for Tomcat Xmx and Xmn value - Crunchify Tips

Step-3

By default you wont see setenv.sh (for Linux/Mac) or setenv.bat (for windows) file under /bin directory. You have to create one with below parameters.

Step-4

  1. Go to command prompt.
  2. Go to <Tomcat Directory>/bin directory
  3. Execute command: ./catalina.sh run

Run Apache Tomcat using catalina.sh run command - Crunchify

Step-5

Monitor logfile and you should see your Tomcat started with all your specified parameters in setenv.sh file.

Apache Tomcat Log with Xmx and Xmn value - Crunchify Tips

PS: For Windows environment you need to create setenv.bat file and run Tomcat with catalina.bat

Join the Discussion

Share & leave us some comments on what you think about this topic or if you like to add something.

OU

Editar vim catalina.sh e adicionar a linha:

export JAVA_OPTS="-Dfile.encoding=UTF-8 -Xms1024m -Xmx6024m -XX:PermSize=256m -XX:MaxPermSize=1024m"

Share and Enjoy !

0Shares
0 0

How to stop Logging on Apache Tomcat6 or Tomcat7 solr server to catalina out

So, according to documentation all logging functionality can be manipulated in logging.properties file which is usually located under apache tomcat root installation folder, which in ubuntu case is under /etc/tomcat6/…

Opening a file you’d probably spot logging level settings (set to FINE as default), well We want to get rid of logging at all, so, according to this helping post I needed to change ConsoleHandler level to OFF.

I changed;

java.util.logging.ConsoleHandler.level = FINE

to

java.util.logging.ConsoleHandler.level = OFF

And happily I got the result Apache Tomcat6 solr server stopped logging to catalina.out

Share and Enjoy !

0Shares
0


0

Spring Boot Tomcat Configuration, migration from container to embedded

I’m migrating a Spring boot application that used to run in the Tomcat container to a Spring Boot application that runs an embedded Tomcat. My old Tomcat configuration has these configurations in the server.xml:
[code type=xml]

I was able to set up most of the properties using a bean
[code type=java]
@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = new TomcatEmbeddedServletContainerFactory();
tomcatEmbeddedServletContainerFactory.setProtocol(“org.apache.coyote.http11.Http11Nio2Protocol”);
tomcatEmbeddedServletContainerFactory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
AbstractHttp11JsseProtocol handler = (AbstractHttp11JsseProtocol)connector.getProtocolHandler();
handler.setMaxKeepAliveRequests(-1);
handler.setAcceptorThreadCount(2);
handler.setMaxHeaderCount(256);
connector.setRedirectPort(8443);
});

return tomcatEmbeddedServletContainerFactory;
}

And application.properties:
[code type=properties]
server.tomcat.accept-count = 500
server.tomcat.max-threads = 600
server.port = 8080
server.max-http-header-size = 32768
server.connection-timeout = 20000

However I cannot figure out how to set this part
[code type=properties]
useComet=”false”
socket.appReadBufSize=”87380″
socket.rxBufSize=”87380″
socket.performanceConnectionTime=”2″
socket.performanceLatency=”0″
socket.performanceBandwidth=”1″
server=”My server”

Can anyone help me please? Thank you

Try this:
[code type=java]
connector.setProperty(“useComet”, Boolean.toString(false));
connector.setProperty(“socket.appReadBufSize”, “87380”);
connector.setProperty(“socket.rxBufSize”, “87380”);
connector.setProperty(“socket.performanceConnectionTime”, “2”);
connector.setProperty(“socket.performanceLatency”, “0”);
connector.setProperty(“socket.performanceBandwidth”, “1”);
connector.setProperty(“server”, “My server”);

Share and Enjoy !

0Shares
0


0

How to change Tomcat to use JDK 7

The current environment is using Tomcat 7 + JDK 6. How to configure Tomcat to use JDK 7?

Environment

  1. Tomcat 7 (apt-get install)
  2. Debian 7.5
  3. JDK 6 and JDK 7

P.S Tomcat 7 is installed via apt-get

Note
You may interest at this tutorial – Apache Tomcat 8 + JDK 8 on Debian

1. Solution

Update the JAVA_HOME in this file /etc/default/tomcat7

1.1 Edit /etc/default/tomcat7, update JAVA_HOME

$ sudo vim /etc/default/tomcat7
/etc/default/tomcat7
#...

# The home directory of the Java development kit (JDK). You need at least
# JDK version 1.5. If JAVA_HOME is not set, some common directories for
# OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
#JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

#...

1.2 Restart Tomcat, done.

$ sudo service tomcat7 restart

1.3 Check this article to find out which JDK is used by Tomcat.

No SPACE, What the F!
Make sure there is no extra space between the equal symbol “=”, it will cause “JAVA_HOME no found”, I spent hours fixing this bug!For example

/etc/default/tomcat7
#...Wrong, SPACE
JAVA_HOME = /usr/lib/jvm/java-7-openjdk-amd64

#...Correct
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

https://www.mkyong.com/tomcat/how-to-change-tomcat-to-use-jdk-7/

Share and Enjoy !

0Shares
0


0

How to fix Tomcat WARNING: An attempt was made to authenticate the locked user?

The warning above means that you fail to authenticate the user tomcat more than once. Tomcat suspects that it is brute force attack on the user tomcat.

What authentication you use in your application? What login-config you use in web.xml of the application?

The default configuration of resourceName “UserDatabase” is the file conf/tomcat-users.xml. Did you change the configuration of resourceName “UserDatabase”?

You can find the configuration of the resource UserDatabase in the file server.xml:

<Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />

By default all users are commented. To be able to work with users from the XML file you should uncomment. Then, you will be able to login with user tomcat:

<tomcat-users>
  <role rolename="tomcat"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
</tomcat-users>

https://stackoverflow.com/questions/15337296/how-to-fix-tomcat-warning-an-attempt-was-made-to-authenticate-the-locked-user

Share and Enjoy !

0Shares
0


0

Gradle plugin supporting deployment of your web application to an embedded Tomcat web container

Share and Enjoy !

0Shares
0 0