'"Observer" pattern for this use case

I have a DAO class that has a method to save in db everytime something in my object changes. When this save happens, i want to kick start another flow that publishes to a SNS topic that an update has happened. I dont believe below is the right approach as these are two seperate tasks and this will just increase the latency of the saveInDB method.

class DAO {
    SNSPublish publishToSNS;
    DynamoDB dynamoDbMapper;

   public void saveinDB(final myObj obj) {
       dynamoDbMapper.save(obj);
       publishToSNS.publish(obj);
   }

I would like to keep the publish part as a separate atomic event, so was wondering what is the easiest way to create an observer in java, that every time a save to DB happens will notify the SNSPublish class to do the publish rather than doing this serially.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source