mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Previously, SimpleInMemoryRepository used a ConcurrentReferenceHashMap to store its locks. The type of map will discard its entries when the JVM comes under GC pressure. With the code in its previous form, this could lead to a NullPointerException when the following occurred: 1. putIfAbsent returned null indicating that a new entry has been added to the map 2. GC pressure caused the map to discard the new entry 3. get returned null as the entry has been discard There are two problems with the existing code: 1. Its usage of a ConcurrentMap is incorrect. The correct usage is: a. Call get to see if the map already contains a lock b. If the lock is null, create a new one c. Call putIfAbsent to add the new lock d. If the return value is non-null, another thread has created the lock and it should be used. If the return value is null, use the new lock created in b. 2. Once the use of ConcurrentMap has been corrected, the fact that it is a ConcurrentReferenceHashMap means that different threads could access the same value using different locks. This would occur if one thread has retrieved a lock from the map and is using it, while GC causes the lock to be removed from the map. Another thread then attempts to get the lock and, as GC pressure has remove it, a new lock is created allowing concurrent access to the same value. This commit updates the code to use the ConcurrentMap correctly and also replaces the ConcurrentReferenceHashMap with a ConcurrentHashMap. This means that the repository will now use slightly more memory but this is outweighed by the benefits of thread-safe updates and no risk of an NPE. Closes gh-6115 |
||
---|---|---|
.. | ||
src | ||
pom.xml | ||
README.adoc |
= Spring Boot - Actuator Spring Boot Actuator includes a number of additional features to help you monitor and manage your application when it's pushed to production. You can choose to manage and monitor your application using HTTP endpoints, with JMX or even by remote shell (SSH or Telnet). Auditing, health and metrics gathering can be automatically applied to your application. The http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready[user guide] covers the features in more detail. == Enabling the Actuator The simplest way to enable the features is to add a dependency to the `spring-boot-starter-actuator` "`Starter POM`". To add the actuator to a Maven based project, add the following "`starter`" dependency: [source,xml,indent=0] ---- <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies> ---- For Gradle, use the declaration: [indent=0] ---- dependencies { compile("org.springframework.boot:spring-boot-starter-actuator") } ---- == Features * **Endpoints** Actuator endpoints allow you to monitor and interact with your application. Spring Boot includes a number of built-in endpoints and you can also add your own. For example the `health` endpoint provides basic application health information. Run up a basic application and look at `/health` (and see `/mappings` for a list of other HTTP endpoints). * **Metrics** Spring Boot Actuator includes a metrics service with "`gauge`" and "`counter`" support. A "`gauge`" records a single value; and a "`counter`" records a delta (an increment or decrement). Metrics for all HTTP requests are automatically recorded, so if you hit the `metrics` endpoint should see a sensible response. * **Audit** Spring Boot Actuator has a flexible audit framework that will publish events to an `AuditService`. Once Spring Security is in play it automatically publishes authentication events by default. This can be very useful for reporting, and also to implement a lock-out policy based on authentication failures. * **Process Monitoring** In Spring Boot Actuator you can find `ApplicationPidFileWriter` which creates a file containing the application PID (by default in the application directory with a file name of `application.pid`).