#Ensuring method ordering in an async method

9 messages · Page 1 of 1 (latest)

fast wasp
#

Hi, I have a question on something.

I have something like this:

@Transactional
@Async 
Public void persistObjects() {
    List<Object> someObjects = apiService.getAllObjects(); 
        repo.saveObjects(someObjects); 
    otherApiService.loadObjects(someObjects); //How can I make sure this call is only called after saveObjects() is done completely mainly because this method is also currently async for performance benefits? 
}
lavish treeBOT
#

This post has been reserved for your question.

Hey @fast wasp! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

silk obsidian
#

the method will execute in same order here unless

#

is saveOjects also async? then you need to block until it finishes

#

@fast wasp

fast wasp
#

saveObjects isn't async. Just realized you're right but one question. if there's an exception or any issue with the save and this is marked as transactional, it would roll back the changes and NOT execute the following load method right?

warm flare
#

yea u can also specify at which exception it should rollback

#

@Transactional(rollbackFor=Exception.class)