Posts for: #Spring-Boot

How to call Spring MongoRepository from an ExecutorService

The problem

Recently I encountered an issue in code when I tried to call the Spring MongoRepository from a non-Spring-managed thread in a Java Spring Boot application. Here is a brief description of the issue.

The Repository interface

public interface ResponseRepository extends MongoRepository<Response, String> {

}

It’s a standard Spring Repository interface without any custom methods.

The calling class

@Component //A Spring Component
public class AnImaginaryComponent {

    @Autowired
    private ResponseRepository responseRepo;

    public void saveResponseInANewThread(Response r) {
        //Create an Executor service
        ExecutorService executor = Executors.newSingleThreadExecutor();

        //Submit a Runnable instance
        executor.submit(() -> responseRepo.save(r));
    }
}

When anImaginaryComponent.saveResponseInANewThread(r) is invoked, it never saves the r Response into the database. And the worst part is that it doesn’t throw any exceptions or print any log messages for the failure.

[Read more]

AMS: Data Provider Service - Generating performance metrics with Spring Boot Actuator

Introduction

This is the first article in a series of upcoming articles on designing and creating an Application Monitoring System. An Application Monitoring System (AMS) is a system that can monitor performance of other running applications. I am building this application component by component from scratch and I will publish it here on this blog. In this post, I talk about how to create and run services that provide application performance metrics using Java, Spring Boot and Docker.

[Read more]