Skip to main content
How to Monitor and Fix Resource Leaks in java ?
Monitor and Fix Resource Leaks
One way to fix resource leaks is straightforward - a periodic restart. It provides good protection against slow resource leaks. But it is also important to spot applications that are draining resources too quickly, so that any software bugs can be fixed.
Leaks that prevent continuous server operation for at least 24 hours must be fixed in the application code, not by application restart.
Common programming mistakes are:
- Not returning the resource to the pool (or not removing it from the pool) after handling an error.
- Relying on the garbage collector to invoke
finalize()
and free resources. Never rely on the garbage collector to manage any resource other than memory.
- Not discarding old object references which prevent recycling the memory occupied by the objects.
Monitoring resource usage should be a combination of code instrumentation and external monitoring utilities. With code instrumentation, calls to an application-provided interface, or calls to a system-provided interface like Oracle Dynamic Monitoring System (DMS), are inserted at key points in the application's resource usage lifecycle. Done correctly, this can give the most accurate picture of resource use. Unfortunately, the same programming errors that cause resource leaks are also likely to cause monitoring errors. That is, you may forget to release the resource, or forget to monitor the release of the resource.
Operating system commands like vmstat or ps in UNIX, provide process-level information such as the amount of memory allocated, the number and state of threads, or number of network connections. They can be used to detect a resource leak. Some commercially available development tools can also be used to find the leak.
In addition to compromising availability, resource leaks and overuse decrease performance.
Comments
Post a Comment