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
2
votes
1 answer

Spring Security @Preauthorize and @Async

I am having the @PreAuthorize("hasRole('ADMIN')") check methods when I am calling from the UI (It will take around 2 to 3 hours meanwhile session is getting expired) I am geetting the SecurityContext as null. Tried with MODE_INHERITABLETHREADLOCAL,…
2
votes
1 answer

Async and shared rabbit template

I have queue config like below @Bean public ConnectionFactory connectionFactory() { CachingConnectionFactory connectionFactory = new CachingConnectionFactory(hostName); connectionFactory.setUsername(mqUsername); …
user3444718
  • 1,485
  • 6
  • 22
  • 32
2
votes
3 answers

@Async with Spring 3.0.6

I am trying to implement an asynchronous call using the @Async annotation. Obviously since its a legacy project, the Spring version is 3.0.6 so it does not support the newer interfaces (AsyncConfigurer) and listeners introduced in later Spring…
Aman Mohammed
  • 2,878
  • 5
  • 25
  • 39
2
votes
1 answer

Spring @EnableAsync breaks bean initialization order?

I wanted to introduce @Async methods (for sending mails in parallel) in my SpringBoot application. But when I put the @EnableAsync annotation on our application's main @Configuration class (annotated with @SpringBootApplication), the Flyway DB…
sorrymissjackson
  • 2,395
  • 1
  • 19
  • 18
1
vote
2 answers

which default pool type of ThreadPoolTaskExecutor in spring

I have read the code but did not find the default pool type of ThreadPoolTaskExecutor. what is the default thread pool of ThreadPoolTaskExecutor? newFixedThreadPool or newCachedThreadPool?
Dolphin
  • 29,069
  • 61
  • 260
  • 539
1
vote
1 answer

How to delay a scheduled task with Spring?

I'd like to create a method that delays the execution on method invocation by 60s. Problem: if the method is called within that 60s, I want it to be delayed again by 60s from last point of invocation. If then not called within 60s, the execution may…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
1
vote
1 answer

Spring @Async method called from within the class

I've an spring component which has some methods as @Async. I want to create a private method and run @Async but it won't works because spring doesn't help self invocation from withing the bean... Is there a simple way to allow a specific private…
Rafael Lima
  • 3,079
  • 3
  • 41
  • 105
1
vote
1 answer

Spring Webflux vs Async

I'm a bit confused about how Webflux is different from Springs @Async. Some pages say that Springs Async Model is blocking, and Webflux is non-blocking. Other pages state that Springs Async is indeed non-blocking. I thought that async can't be…
Gg5g4
  • 11
  • 1
1
vote
1 answer

Async Transactional Saves do not work in Spring after upgrade

We upgraded Spring Boot from 1.5.8 to 2.6.2. It has introduced a problem that has us perplexed: Transactional saves are not processing from inside spawned threads. We use JPA managed entities on a Mysql database and make calls down to the…
IcedDante
  • 6,145
  • 12
  • 57
  • 100
1
vote
1 answer

How to intercept configuration of all ThreadPoolTaskExecutors?

I'd like to intercept the creation of all ThreadPoolTaskExecutors inside the application context, and add all of them a custom TaskDecorator. Pseudocode: public void interceptTaskExecutors(List executors) { var decorator…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
1
vote
0 answers

Spring boot @Transactional and @Async not working together

I am trying to make a function transactional by using the spring's @Transactional annotation. The function is something like this @Transactional public void doSomething() { recordActionInDb(); updateThirdPartyApi(); } recordActionInDb: is…
1
vote
0 answers

Start Spring Batch job in Async method throws lazy exception

I need to start spring batch job in Async method, but I got lazy exception in item processor: This is my Approach: Service that contains Async method looks like: @Service @RequiredArgsConstructor @Slf4j public class BatchService { …
zafirov
  • 392
  • 1
  • 3
  • 18
1
vote
1 answer

Async on different class with same Threadpool SpringBoot

I have configured 1 threadpool @Async(value="pool_1"). now I want to use this threadpool in different classes, so I put @Async(value="pool_1") above my 2 different class. I just want to get confirmation like it won't create 2 seperate pool of…
1
vote
1 answer

What happens if my thread sleep is greater than the keep alive seconds when the thread pool is full?

I have a spring boot application where a users hits an endpoint and I have to acknowledge that I got their request immediately. I need to do some computation on different thread and send them response on a different endpoint after my computation is…
Saugat Dahal
  • 39
  • 1
  • 10
1
vote
0 answers

How do I use ThreadLocalTargetSource in a TaskDecorator?

We are using Spring's ThreadLocalTargetSource to set some Tenant context information into a bean and propagate it through a typical HTTP request or received event. The approach is similar to what is described…
IcedDante
  • 6,145
  • 12
  • 57
  • 100