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
54
votes
6 answers

JUnit-testing a Spring @Async void service method

I have a Spring service: @Service @Transactional public class SomeService { @Async public void asyncMethod(Foo foo) { // processing takes significant time } } And I have an integration test for this…
Abdull
  • 26,371
  • 26
  • 130
  • 172
12
votes
4 answers

Spring @Async propagate context information

I've a Spring Boot 2.2 application. I created a service like this: @Async @PreAuthorize("hasAnyRole('ROLE_PBX')") @PlanAuthorization(allowedPlans = {PlanType.BUSINESS, PlanType.ENTERPRISE}) public Future saveCDR(Cdr3CXDto cdrRecord) { …
drenda
  • 5,846
  • 11
  • 68
  • 141
12
votes
3 answers

Call async service which return DeferredResults, multiple times without increasing execution time

my applications should have 2 core endpoints: push, pull for sending and fetching data. Pull operation should works asynchronously and result DeferredResult. When user call pull service over rest, new DefferedResult is created and stored into…
Denis Stephanov
  • 4,563
  • 24
  • 78
  • 174
11
votes
6 answers

Spring @Cacheable and @Async annotation

I have the need to cache some the results of some asynchronous computations. In detail, to overcome this issue, I am trying to use Spring 4.3 cache and asynchronous computation features. As an example, let's take the following code: @Service class…
riccardo.cardin
  • 7,971
  • 5
  • 57
  • 106
10
votes
1 answer

Spring async doesn't work when implements AsyncConfigurer

Having a Spring configuration class for async methods as: @Configuration @EnableAsync(proxyTargetClass = true) @EnableScheduling public class AsyncConfiguration { @Autowired private ApplicationContext applicationContext; @Bean public…
Ignasi
  • 5,887
  • 7
  • 45
  • 81
9
votes
6 answers

What are the defaults in Spring @Async?

Could you tell me what are the default parameters for Spring @Async ThreadPoolTaskExecutor or how can I find them one my own? What are the default values for maxPoolSize, corePoolSize, and queueCapcity? Should I override them to improve my…
Pasha
  • 1,768
  • 6
  • 22
  • 43
9
votes
2 answers

Spring Flux and the Async annotation

I have a Spring Flux application where at some point I need to execute some heavy task on the background, the caller (a HTTP request) does not need to wait until that task completes. Without reactor, I would just probably use the Async annotation,…
Jonathan Naguin
  • 14,526
  • 6
  • 46
  • 75
9
votes
2 answers

Spring @Async method call inside @Scheduled method

I am using Spring boot with @EnableScheduling and @EnableAsync. I have a method which is annotated with @Scheduled. I have a few more methods, which are annotated with @Async. Now I am calling these @Async methods in the @Scheduled method and…
Soumitri Pattnaik
  • 3,246
  • 4
  • 24
  • 42
7
votes
4 answers

How to run @PostConstruct non-blocking in Spring?

@PostConstruct public void performStateChecks() { throw new RuntimeException("test"); } If I start a spring application with code above, it will prevent the application to start. What I'm looking for is to execute a method directly after…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
7
votes
2 answers

java.sql.SQLNonTransientException: [Amazon][JDBC](10900) Not all parameters have been populated

I am building a Spring Boot application that is multithreaded utilizing the Spring @EnableAsync and @Async annotations. When I run the application with a single thread (CorePoolSize 1, MaxPoolSize 1) everything works as expected. When I increase the…
Cosmtar
  • 516
  • 5
  • 14
7
votes
1 answer

How to catch transaction exceptions in @Async?

When writing transactional methods with @Async, it's not possible to catch the @Transactional exceptions. Like ObjectOptimisticLockingFailureException, because they are thrown outside of the method itself during eg transaction…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
6
votes
1 answer

@Scheduled and @Async are sharing same threadpool in spring-boot

I have configured two different thread pools, one for @Scheduled and other for @Async. However, I notice that the thread-pool for @Async is not being used. Here is the Scheduler configuration @Configuration @EnableScheduling public class…
5
votes
0 answers

what happens when a Spring @Async thread never completes?

If you have an @Async method the returns a CompletableFuture....and the future never gets completed, does spring just leak the thread? Yes, I know whomever is waiting on the results could timeout and assume exceptional completion for latter…
5
votes
3 answers

Async on spring boot rest rest api - annotation should be on service only or controller

I have to implement a method with async features in spring boot: I am a bit confused regarding the location of the annotation asyn, basically my rest controller is as follows: @RestController @RequestMapping("/email") public class EmailController…
user1999453
  • 1,297
  • 4
  • 29
  • 65
5
votes
5 answers

Asynchronous REST API generating warning

I am working with a Spring boot application. I have a rest controller that returns Callable. @GetMapping("/fb-roles") @Timed public Callable> getAllFbRoles() { log.debug("REST request to get all FbRoles"); return (() -> { return…
Arif Rabbani
  • 131
  • 1
  • 2
  • 12
1
2 3
9 10