0

I have two services Regular and Adhoc and they both can be invoked concurrently, later it will process method will get the corresponding objects for DB and Kafka using mapstruct mapper and save them to DB/push to kafka.

AdhocService{
    @Autowired
    ProcessPayload processPayload;

    processPayload.process(payload);    
}
RegularService{
    @Autowired
    ProcessPayload processPayload;

    processPayload.process(payload);    
}

ProcessPayload{

    process(Payload payload){
        dbObject = payload -> dbObjectMapper
        DBopertion(dbObject);

        kafkaObject = payload -> kafkaObjectMapper
        KAFKAopertion(kafkaObject);
    }

}

Can Springboot's singleton bean support this concurrent execution without any issue? If not then what is the alternative? - creating two beans of ProcessPayload and inject them using @Qualifier? I checked this but not able to interpret it specifically.

ray.10may
  • 1
  • 3
  • This code wouldn't even compile. As long as there is no state being held at the instance level there is no issue, however that is not clear from the pseudo code you have written here. – M. Deinum Jun 13 '23 at 18:14

0 Answers0