Six Core Tomcat Interview Questions and Answers

This article presents six essential Tomcat interview questions covering default ports, connector modes, deployment methods, servlet instantiation, performance optimization techniques, and key configuration elements, providing concise explanations and code examples for each topic.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Six Core Tomcat Interview Questions and Answers

As the peak hiring season approaches, many candidates are preparing for interview "cram sessions"; this article compiles six core Tomcat interview questions with answers to help readers confidently tackle most interview scenarios.

1. What is Tomcat's default port and how to change it?

The default port is 8080; you can modify it by editing the Connector element's port attribute in the conf/server.xml (or service.xml) file.

2. What connector operating modes does Tomcat have (optimizations)?

Tomcat supports three connector modes: BIO: one thread per request, simple but resource‑intensive; default in Tomcat 7 and earlier on Linux. NIO: Java non‑blocking I/O, allowing few threads to handle many requests; default in Tomcat 8.0.x. To enable in Tomcat 7, adjust the connector configuration:

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" redirectPort="8443"/>
APR

: Apache Portable Runtime, solves OS‑level I/O blocking; used by default on Windows 7+ for Tomcat 7/8.

3. What deployment methods does Tomcat support?

Automatic deployment: copy the web application into the webapps directory (not recommended for production).

Manager App: use the web console to deploy a WAR file or specify an application path.

Direct conf/server.xml deployment: add a Context element to the file.

Custom deployment descriptor: place an xyz.xml containing a Context node under conf/Catalina/localhost/.

4. How does Tomcat create servlet class instances and what principle is used?

When the container starts, it parses each web application's web.xml, loads the servlet classes, and instantiates them via reflection (or on first request).

If the load-on-startup value is positive, the servlet is instantiated at startup; otherwise it is created on first request.

5. How to optimize Tomcat?

Performance is closely tied to user experience; common optimizations include:

Monitor web.xml and pre‑compile JSPs to servlets; allocate sufficient JVM memory.

Ensure adequate CPU, memory, and disk resources; use caching and compression (e.g., Nginx as a front‑end cache and gzip).

Employ clustering for horizontal scaling, sharing sessions across multiple Tomcat instances.

Increase maxThreads and acceptCount in the connector:

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" acceptCount="500" maxThreads="400"/>

Configure a thread pool via an Executor and reference it in the connector:

<Executor name="tomcatThreadPool" namePrefix="req-exec-" maxThreads="1000" minSpareThreads="50" maxIdleTime="60000"/>
<Connector port="8080" protocol="HTTP/1.1" executor="tomcatThreadPool"/>

Speed up startup by removing unused web apps, disabling WebSocket jars, and setting -Djava.security.egd=file:/dev/./urandom for faster random number generation.

Memory tuning using JVM options such as -Xms, -Xmx, -XX:MaxNewSize, and adjusting PermGen/Metaspace as needed.

6. Which Tomcat configuration elements should you be familiar with?

Key elements include: Context: represents a web application; attributes like docBase, path, reloadable, useNaming, workDir, swallowOutput, debug. Host: virtual host with attributes name, appBase, unpackWARs. Logger: logging configuration with className, prefix, suffix, timestamp.

Conclusion

The six questions covered are:

Default port and modification method.

Connector operating modes.

Deployment methods.

Servlet instantiation mechanism.

Optimization strategies and familiar configuration items.

Reflect on how many of these you can answer confidently.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaoptimizationConfigurationWeb serverTomcat
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.