I want to implement a simple servlet that makes every n minutes some validation on a web application. The purpose of this validations is to return a http status code to a load balancer. The load balancer can now if certain node can be used or not.
Is my solution (using a servlet) feasible? What do you propose and moreover how can a heartbeat can be embedded into a Java servlet?
I'm using Java EE technologies.
Typically the load balancer will make a HTTP request to your servlet. If it answers 200 OK (or includes something in the payload that the load balancer looks for) then the application is healthy; if not the load balancer stops routing traffic to it until it becomes healthy again. In other words it is very feasible and you don't need to do anything special at all. Just answer a normal request and configure the load balancer to make the right call.
I would poll every x seconds rather than minutes, but that depends on the application. Perhaps your users can tolerate a minute's downtime.