Michael Fletcher
Michael Fletcher

Reputation: 117

Spring Async and timeshares

I'm trying to create an architecture using Java Spring which will have several background processes which will be running concurrently, listening and pulling information as it arrives from different ZMQ sockets.

I'm not sure the best way to do this. Right now, i'm using the @Async annotation with a TaskPoolExecutor, but the @Async function seems to be blocking the next function call in the stack.

So my questions are 1) Will an @Async function block the next function call in the stack? Or will it fire off that function in a new thread, and continue executing the functions in the current thread. 2) Is there any way to give each Thread an equal timeslice of computing power. 3) Are there any better ways to do this?

Thanks!

Upvotes: 0

Views: 33

Answers (1)

Ilya Zinkovich
Ilya Zinkovich

Reputation: 4410

  1. @Async will run the annotated method asynchronously using the specified executor.
  2. There is no way to control OS resources dedicated to threads.
  3. Java has a very convenient CompletableFuture API for asynchronous computations. I've recently wrote a blog post about the problems with @Async and how they can be solved with CompletableFuture: Demystifying the Magic of Spring: @Async .

Upvotes: 1

Related Questions