Questions tagged [spring-async]

Asynchronous execution in spring for Java. Annotating a method of a bean with @Async will make it execute in a separate thread i.e. the caller will not wait for the completion of the called method.

Asynchronous execution in spring for Java. Annotating a method of a bean with @Async will make it execute in a separate thread i.e. the caller will not wait for the completion of the called method.

150 questions
0
votes
0 answers

spring boot use jpa inside async

I'm developing a small spring boot app using Jpa and @Async and I'm having this situation, where I call a Repository inside the @Async scope to save some new entities into the database and this is how it's done: @Override public void…
0
votes
1 answer

How do I access RequestContextHolder in Spring AOP Before or After advice which are asynchronous

BeforeAspect.java @Aspect @Component @EnableAsync public class BeforeAspect { @Pointcut("@annotation(com.example.demo.api.EventLog)") public void eventLogControllers() {} @Before("eventLogControllers()") @Async public void…
Alison
  • 31
  • 3
0
votes
1 answer

Conflict with config class in dependency (Spring AsyncConfig)

My team uses some starter code that's included in every internal Spring project by default. This is included as a dependency (not parent) in the pom.xml file of my project. This starter code contains a default implementation of a configuration…
0
votes
0 answers

Spring-Boot @Async: How to figure out actual method name annotation with @Async at runtime?

I need to figure out the @Async method name in TaskDecorator. How do I figure out the method name (asyncMethodWithReturnType) from TaskDecorator or I there a better way to figure out the actual method that is annotated with @Async in Spring Boot…
Bmis13
  • 550
  • 1
  • 8
  • 27
0
votes
2 answers

Can I return an API response without waiting on other external API calls in Spring Boot?

Is this the correct way to use @Async in Spring Boot? @Service class someServiceImpl { ... public someResponseDTO getUsers(int userId) { // Do some logic ... // Call external API with another service method from another service impl …
isoplayer
  • 67
  • 2
  • 7
0
votes
2 answers

Java Spring Async Exception Handling for methods with non void return value

I have an async function which does a particular task, sample code below, @Async public CompletableFuture foo(String value) throws Exception { // do task LOGGER.info("Processing completed"); return…
NitishDeshpande
  • 435
  • 2
  • 6
  • 19
0
votes
0 answers

Can I use different executor for each @Async method call?

In a spring component, i have this method: @Async("@taskExecutorFactory.getOrCreate(#taskId)") public void updateTask(String taskId) { // update code } I would like to use a different executor for each call. The executor is provide by the…
zguesmi
  • 321
  • 1
  • 11
0
votes
1 answer

Spring @Async fails with rejectedExecutionexception

We need to run task in parallel so we are using spring @Async feature. To provide executor config we are creating a Executor bean. @Bean(name = "async") public Executor threadPoolTaskExecutor() { ThreadPoolTaskExecutor executor = new…
pvjhs
  • 549
  • 1
  • 9
  • 24
0
votes
0 answers

De-queuing a message from JMS Queue only when a thread in a threadpool is available to process it

The requirement is to listen on a JMS Queue and process the requests in a asynchronous manner and send a response on a different JMS Queue. The system is only allowed to process a fixed number of requests at a single moment. A request must not be…
ArmenHeat
  • 111
  • 8
0
votes
1 answer

Are there any difference for web browser when backend use webflux or simple rest controller?

Assume we have a 2 rest services: // a rest controller @GetMapping private List getAllEmployees() { return employeeRepository.findAllEmployees(); } // another controller @GetMapping private Flux getAllEmployees() { …
0
votes
1 answer

Spring boot 2.2.6 doesn't bootstrap if both @EnableAsync and @EnableWebSocketMessageBroker are used

I'm trying to use Web Sockets and @Async tasks. So I created 2 configuration classes: @Configuration @EnableWebSocketMessageBroker public class WebSocketConfig { } @Configuration @EnableAsync public class AsyncConfiguration { } I also have a…
Beto Neto
  • 3,962
  • 7
  • 47
  • 81
0
votes
0 answers

Launching Spring batch job asynchronously without configuring JobLauncher

I am aware you can Asynchronously kick of job by configuring the JobLancher with TaskExecutor: @Configuration public class BatchConfig extends DefaultBatchConfigurer { @Bean public TaskExecutor getAsyncExecutor() { …
M06H
  • 1,675
  • 3
  • 36
  • 76
0
votes
0 answers

Spring Boot Async thread Not completing the Task

I have been working on a crawler where I have to make 1000+ request on some particular server. So far It was working nicely. But now the async task is not getting completed. Here is my sample code. private static CloseableHttpClient httpclient =…
0
votes
0 answers

Spring @Async with Delay

I am trying to define an Async method using Spring that needs to be called at the end of a synchronous function, like below: void syncFunction() { ... asyncFuntion(); } @Async void asyncFunction() { ... } I need to add a delay of…
0
votes
0 answers

Spring Framework @Async method + MySql Performance Degradation - Scalability Problem

I've an api, notifyCustomers() implemented on my batch server which gets called from my application server. It can send notification via three channels SMS, Push & Email. I've separate helper classes for each of them and they all execute in async…
Vishal Pawale
  • 3,416
  • 3
  • 28
  • 32