The JVM is fast, mature and well instrumented, but it treats memory differently from most runtimes: it reserves a heap, uses additional native memory for threads, metaspace and buffers, and tunes itself based on what it detects about the machine. On a VPS, where memory is shared with a database and the OS, getting those numbers right is the main job. This guide covers that, plus collectors, pools and monitoring. Deployment steps are in our Spring Boot guide.
Choose a JDK
Use a long-term-support release (Java 17, 21 or newer LTS) from a maintained distribution such as Eclipse Temurin, Amazon Corretto or your Linux distribution's OpenJDK packages. Newer JDKs bring faster startup, better garbage collectors and container awareness. Pin the version and update it for security releases, which come quarterly.
Memory: Heap and Everything Else
| Area | What uses it | Controlled by |
|---|---|---|
| Heap | Your objects | -Xmx / -XX:MaxRAMPercentage |
| Metaspace | Class metadata | -XX:MaxMetaspaceSize (optional cap) |
| Thread stacks | Each thread, often ~1 MB reserved | -Xss, thread pool sizes |
| Direct buffers | Netty, NIO | -XX:MaxDirectMemorySize |
| Code cache, GC structures | JIT-compiled code, collector bookkeeping | Mostly automatic |
The process uses noticeably more than -Xmx. A practical rule: give the heap about 60–75% of the memory budget for the service, and leave the rest for native memory. On a dedicated 8 GB server that also runs PostgreSQL, a 2–3 GB heap for one service is a reasonable start.
# systemd unit
Environment="JAVA_TOOL_OPTIONS=-Xms1g -Xmx3g -XX:+ExitOnOutOfMemoryError -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/tmp"
MemoryMax=4500M
Without explicit settings, the JVM's default maximum heap is a quarter of the memory it detects, which can be too small on a dedicated server and too large when several JVMs share one. In containers, -XX:MaxRAMPercentage=70 sizes the heap relative to the container's limit. ExitOnOutOfMemoryError lets systemd restart a broken process cleanly instead of leaving it half-working.
Choosing a Garbage Collector
| Collector | Strength | Use when |
|---|---|---|
| G1 (default) | Balanced throughput and pauses | Most services with heaps from hundreds of MB to tens of GB |
| ZGC (generational in recent JDKs) | Very short pauses, scales to large heaps | Latency-sensitive services, large heaps |
| Parallel | Highest throughput, longer pauses | Batch jobs where pauses do not matter |
| Serial | Minimal overhead | Tiny services with very small heaps |
Start with G1 and measure pause times in GC logs (-Xlog:gc*:file=/var/log/app/gc.log:time,uptime:filecount=5,filesize=20m). Switch only when data shows pauses are a problem.
Threads and Pools
- Web server threads (Tomcat, Jetty): defaults of around 200 threads suit blocking I/O; reduce them on small servers to save memory and protect the database.
- Virtual threads (Java 21+): enable them in frameworks that support them (Spring Boot 3.2+:
spring.threads.virtual.enabled=true) to handle many concurrent blocking requests with little memory. The database pool remains the real limit. - Connection pool (HikariCP): size from what the database can serve, often 10–30, not from the number of threads.
- CPU-bound executors: about one thread per vCore.
Startup Time
JVM applications can take seconds to start and warm up the JIT. That matters for deploys and restarts. Mitigations: Class Data Sharing archives (-XX:SharedArchiveFile, or Spring Boot's CDS support), lazy initialisation where safe, and zero-downtime deploys that start the new instance before stopping the old one (see our zero-downtime guide). GraalVM native images start in milliseconds but trade peak throughput and some library compatibility.
Monitoring with JFR and Metrics
# record 2 minutes of production profiling with low overhead
jcmd $(pgrep -f app.jar) JFR.start duration=120s filename=/var/tmp/app.jfr
# quick checks
jcmd $(pgrep -f app.jar) GC.heap_info
jcmd $(pgrep -f app.jar) Thread.print | head -50
Java Flight Recorder has low overhead and is designed for production; open recordings in JDK Mission Control. Expose JVM metrics (heap, GC pauses, threads) through Micrometer and Prometheus, and alert on heap usage after GC trending upwards, which indicates a leak.
CPU and the JIT
The JIT compiler uses CPU during warm-up and benefits from more than one vCore. The JVM detects available processors and sizes GC and JIT threads accordingly; on a 2-vCore plan, GC and compilation compete with request handling during startup, which is normal and settles after warm-up.
Security and Updates
Apply quarterly JDK security updates, keep frameworks and libraries current (dependency checkers in the build flag known vulnerabilities), run the service as an unprivileged user, keep actuator or management endpoints on localhost or behind authentication, and never expose JMX remotely without authentication and TLS.
Sizing
| Setup | EPYC plan |
|---|---|
| One Spring Boot service + PostgreSQL | 2 vCores / 8 GB |
| Two or three services, Redis and a database | 4 vCores / 16 GB |
| Large heaps, Kafka/Elasticsearch, many services | 8–16 vCores, 32–64 GB |
Deploying JVM Services
Package the application as an executable JAR (or a container image), deploy it into a release directory, and restart the systemd service. Because JVMs take a few seconds to start and longer to warm up, run two instances behind Nginx and restart them one at a time for zero-downtime deploys, and configure a readiness check so traffic only reaches an instance once it is ready (Spring Boot exposes readiness and liveness health groups for this).
Common Mistakes
- No explicit heap size, so the JVM picks a default that is too small or too large for the server.
- Setting
-Xmxto nearly all the RAM, leaving nothing for native memory, the OS or the database. - Huge thread pools and connection pools that overwhelm the database.
- Running an outdated JDK that no longer receives security updates.
Next Steps
Set the heap and collector explicitly, enable GC logging and metrics, and load test before launch; then adjust with real data.
In Short
Budget memory for heap and native use, keep G1 unless data says otherwise, and size pools to the database.
SkyRainCloud Plans for This Workload
JVM applications reserve memory up front: a Spring Boot service with a database is comfortable on 2 vCores / 8 GB; several services or large heaps fit better on 4–8 vCores with 16–32 GB. Leave room outside the heap for native memory, the OS and the database.
AMD EPYC 7C13 VPS
Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — AMD | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Websites, small APIs, bots, staging and VPN servers | Order |
| VPS 2 — AMD | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,299/month | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| VPS 3 — AMD | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,499/month | Production databases, high-traffic sites, multi-container apps | Order |
| VPS 4 — AMD | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,899/month | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.