Resource handling is how an application manages finite system resources such as memory, CPU, database connections, and threads while serving requests. How well these are managed directly determines throughput, latency, and stability under load.
Key Points: • Unclosed resources like database connections or file streams cause leaks that degrade performance over time and can eventually exhaust a connection pool. • Connection pooling (e.g. HikariCP) and thread pool sizing (e.g. Tomcat's max threads) control how many concurrent requests an app can handle without overwhelming the JVM or database. • Excessive object creation increases garbage collection pressure, which shows up as latency spikes under load. • Caching frequently accessed, rarely changing data reduces redundant CPU and I/O work. • Monitoring tools like Actuator metrics or a profiler help catch resource bottlenecks before they cause outages in production.
Example: An endpoint that opens a new database connection per request without a pool will work fine in testing but collapse under real traffic once the database's max-connections limit is hit, causing cascading timeouts.
Interview Tip: A concise interview answer is:
"Good resource handling means using pooling for expensive resources like database connections, sizing thread pools appropriately, and avoiding leaks by always closing what you open. Poorly managed resources don't show up in dev, but they cause latency spikes, exhausted connection pools, and outages once real traffic hits the app."