I need assistance.
An issue with one of my endpoints timing out is causing me distress.I did some performance tweaking with SQL and other REST services I am using but it only helps a little bit.A nice solution for this problem, I thought, would be to use some of the Async capabilities of Spring Boot and Java 8 and perform some sort of "Fire and forget" action.
I tried something like that, but it is no good, the "Time to rock!" message gets printed out all right but it seems that getLyrics() method is not invoked at all!
//MyController.java @GET @Path("na/na/na") @Produces({"application/json"}) public Response getLyrics() { final String lyrics = delegate.getLyrics(); return Response.ok().entity(lyrics.isEmpty()).build(); } //MyDelegate.java @Async("threadPoolTaskExecutor") public Future<Boolean> getLyrics() { LOG.info("Time to rock!"); final boolean result = lyricsService.getLyrics(); return new AsyncResult<Boolean>(result); } //MyAsyncConfig.java @Configuration @EnableAsync public class MyAsyncConfig { @Bean(name = "threadPoolTaskExecutor") public Executor threadPoolTaskExecutor() { return new ThreadPoolTaskExecutor(); } }So, lyricsService.getLyrics() (that is not being called for some reason) does all the work, calls other services, fetches stuff from the SQL database, and performs calls against some other REST endpoints. All of this takes time and sometimes* causes a timeout. I would like it to process in peace, and if possible, return some sort of response when possible.
I tried several variations of this solution as it seems to be close to what I need, but can't seem to get why it is not working for me.
*often