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

Async Bean initialization

Initialization of a specific bean requires performing a network connection. This may take some time, and unnecessarily blocks the already long startup by a few seconds. Is there any way for my bean to signal that it isn't yet initialized even after…
f.khantsis
  • 3,256
  • 5
  • 50
  • 67
5
votes
1 answer

JUnit rollback transaction with @Async method

I am writing an integration test using SpringJUnit4ClassRunner. I have a base class: @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration({ /*my XML files here*/}) @Ignore public class BaseIntegrationWebappTestRunner…
dty
  • 466
  • 2
  • 6
  • 17
5
votes
1 answer

How to integrate Spring Retry with AsyncRestTemplate

How can you integrate Spring Retry with external calls with AsyncRestTemplate? If it's not possible, is there another framework that supports it? My use case: public void doSomething() throws ExecutionException, InterruptedException { …
Glide
  • 20,235
  • 26
  • 86
  • 135
4
votes
3 answers

Not getting response body when using ContentCachingResponseWrapper

I have a Springboot API in Scala with multiple endpoints. All endpoints are async and return DeferredResult. I want to use filters to log response body in some cases. I have created a filter with order 1 to cache requests and response as…
nishantv
  • 643
  • 4
  • 9
  • 27
4
votes
2 answers

Best way to limit time execution in a @RestController

Considering the following code: @RestController @RequestMapping("/timeout") public class TestController { @Autowired private TestService service; @GetMapping("/max10secs") public String max10secs() { //In some cases it can…
4
votes
2 answers

Which TaskExecutor to use for async logging?

I have a REST webservice and want to log any incoming and outgoing XML requests. As they can be quite large and I also have to apply some sort of transformation, I'd like to execute that in an async thread. So far I'm just using @Async annotation on…
membersound
  • 81,582
  • 193
  • 585
  • 1,120
4
votes
2 answers

Spring Async: How to call spring hateoas ControllerLinkBuilder inside Async method

I am calling ControllerLinkBuilder.linkTo method inside a spring Async method and it fails to find the current request. service.setUrl(linkTo(Controller.class, Controller.METHOD_GET, headers.getFirst(HEADER_SOURCE),…
Manan
  • 303
  • 1
  • 6
3
votes
1 answer

Are CompletableFutures thread safe?

I have a thread that invokes two separate threads. It passes in the same CompletableFuture to both of those child threads. If .get() was called in both of those threads at the exact same time, would I get any type of concurrency issues? could it…
Brian
  • 556
  • 6
  • 26
3
votes
2 answers

How to test for Exception in @Async method?

How can I assert that a certain exception is thrown inside an @Async method? Because the following exception is caught by Springs SimpleAsyncUncaughtExceptionHandler. @Service public class Service { @Async public void run() { …
membersound
  • 81,582
  • 193
  • 585
  • 1,120
3
votes
2 answers

How to run Spring boot tests concurrently?

I have multiple Spring Tests, that are executed one-by one, while I would like to run them concurrently. Code sample: @SpringBootTest @RunWith(Suite.class) @Suite.SuiteClasses({ Test1.class, Test2.class, Test3.class, …
3
votes
1 answer

Testing Spring's @Async void-returning methods

I have a little problem with @Async methods that return void (or Unit, I'm writing in Kotlin) in my Spring app. I don't know why, but when @Async method returns void it just doesn't execute, or at least it doesn't do what it is supposed to. Need to…
Maroš Šeleng
  • 1,600
  • 13
  • 28
3
votes
1 answer

Spring Boot ASync + AutoWired Executor vs manual Executor + Future/Callable?

Is there a drawback to creating and managing your own ExecutorService vs using Spring Boot's @Async on a method with an @Bean method to create an Executor? To me, doing it manually seems much simpler. I simply create my ExecutorService and a method…
Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
3
votes
1 answer

providing timeout execution for a Spring AOP Aspect

How I can provide a timeout execution to a Spring AOP Aspect ? The logger method of MyAspect shouldn't take more time execution than 30 seconds, if not i would want to stop the method execution. How i can do this ? MyAspect Code :…
user2602584
  • 737
  • 2
  • 7
  • 25
3
votes
0 answers

Testing ASync method with JUnit in Spring MVC

I have a scenario where i need to test async method. I have XML based configuration and is looks like below
EagerToLearn
  • 89
  • 12
3
votes
1 answer

Spring Async method or event throws HystrixRequestContext.initializeContext() exception

Our code has a few @Async methods, and ApplicationListeners. These classes and methods end up calling API services that have the @Hystrix annotation. These calls throw the following exception: java.lang.IllegalStateException:…
nsdiv
  • 912
  • 12
  • 30
1
2
3
9 10