user3928830
user3928830

Reputation: 1

Spring @Asnyc method call and threadsafety for arguments passed to async methods

I wanted to ask how Spring @Async annotated methods do handle with objects passed as a arguments. The async method execution will create another thread. In this case the caller and the new thread have both a reference to the objects passed in as arguments. That means both threads are able to mutate the same objects. This may lead to false results. I wanted to ask how Spring is handling this. Maybe the objects passed in as arguments are somehow copied/cloned?

Thanks in advance :)

Upvotes: 0

Views: 2202

Answers (1)

Spring is not even try to handle it. It is your responsibility as a developer to implement the method so it works correctly in concurrent environment. Accessing shared data is a general problem (or I would say implication) of concurrency which has its solutions.

Upvotes: 3

Related Questions