0
Hello,
I’m having doubts as to which solution I could apply to the following problem:
I built an API that when called makes several calls in some databases and after composing and concatenating the data it makes a call to another API to which I am client, passing as parameter the data I obtained at the beginning of the process. The problem is that my API will be called by several users and this causes it to get lost, this is before concluding the first call it is already manipulating data of the second bringing wrong results.
Questions:
1) There is a way to stop the initial API method so that it only starts a new execution if it completes the execution in progress?
2) Or there is how it runs in parallel with other calls of itself receiving different parameters?
Here’s a brief example of the methods I’m trying to run in parallel or sequential.
public string ChamadaInicialDaAPI(string paramInic)
{
string retApi = IniciaProcessoApi(paramInic);
return retApi;
}
private string IniciaProcessoApi(string paramInic)
{
lock (this)
{
string strPesq1 = “”;
string retApiExt = “”;
DAL.ProcessaDados logs = new DAL.ProcessaDados();
strPesq1 = logs.PesquisaDados(paramInic);
BLL.EnviaDados sendData = new BLL.EnviaDados();
retApiExt = sendData.EnviaRequisicaoApiExterna(strPesq1);
return retApiExt;
}
}
https://answall.com/q/1946/101. Almost every lock loses the advantage it had and can create other problems. And use thread It is extraordinarily complicated, you must avoid until it is absolutely necessary, even the experienced make a big mistake doing it. Even because the code could be more efficient to improve performance without needing to thread, It’s not much, but there are expensive things you didn’t have to do. I do not even know if it is necessary or needs a lock, the question does not make clear the real situation.
– Maniero
Thanks for the Maniero note, basically I need my API to run sequentially on the server (FIFO) or run parallel on the server without one processing interfering with the other...
– Cleber Pessoal
Do you use any architectural concept of the application? CQRS?
– Julio Borges
Julio Borges, basically I make use only of the concept of layers, as my term this relatively short I am creating an application on the server that will manage the queue. Thank you.
– Cleber Pessoal
The problem is not in the routine of
ProcessaDados()
? I suppose it generates the mass for thePesquisaDados()
, but you would be generating a different mass , upon receiving a new request before having researched the first?– Leandro Angelo