concurrent transactions spring boot + Docker

Asked

Viewed 147 times

0

I have an app on with Jhipster(Spring Boot + Angular) where Gero protocols for service.

I’m using the @Transactional in the class of generating the protocols for control in the generation of transactions but I am still having problems duplicated data due to amount of people using the application at the same time. I thought of a table implementation for control where I would keep the date and number of pre-selected vacancies.

As a second option we found Apache Kafta to help control transactions.

Who has a better idea to control the transactions since they are distributed I am waiting.

Code :

@Service
@Transactional
public class ProtocoloService {

    private final AgendamentoRepository agendamentoRepository;

    public ProtocoloService(AgendamentoRepository agendamentoRepository) {
        this.agendamentoRepository = agendamentoRepository;
    }

    @Transactional
    public String gerar() {

        return gerar(getInicial());
    }

    private String gerar(String inicial) {
        List<Agendamento> agendamentoList = agendamentoRepository.findAgendamentoByProtocoloStartingWith(inicial);
        if(agendamentoList.isEmpty()) {
            return inicial + "000001";
        } else {
            Agendamento maior = agendamentoList.stream().max(Comparator.comparing(Agendamento::getProtocolo)).get();
            Long numeral = Long.valueOf(maior.getProtocolo().substring(6))+1;
            return inicial + StringUtils.leftPad(String.valueOf(numeral), 6, "0");
        }
    }

    private String getInicial() {
        String ano = String.valueOf(LocalDate.now().getYear()).substring(2);
        String mes = StringUtils.rightPad(String.valueOf(LocalDate.now().getMonthValue()),2,"0");
        String dia = StringUtils.rightPad(String.valueOf(LocalDate.now().getDayOfMonth()),2,"0");
        return ano+mes+dia;
    }
}
  • 1

    You said that you are having problems, can you be more specific with the problems, mention all of them (besides the problem of competition)? , You quoted the words Vague, I did not understand the context. What is the distribution structure of your application? , What is the spring boot version?

  • @Erickluz edited, but the title already cites the problem...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.