1
I have a service today that I need to calculate its running time with multiple accesses, so I’m trying to run simultaneous threads and log that time, the problem is that for the run method of the Thread class I cannot pass parameters and in case I need these parameters to run the service. How can I do that? Am I on the right track? Follow code:
for(int x = 0; x<50 ; x++){
new Thread() {
long tempInicial = System.currentTimeMillis();
@Override
public void run(HttpServletRequest request,
HttpServletResponse response, String sequence,
CommandMapping commMapping, CommandForm form) throws FactoryException { //ERRO -> Não posso ter esses parâmetros
Command command = CommandFactory.getInstance().getCommand(
commMapping.getCommandPath());
CommandResponse commResponse = null;
try {
commResponse = command.executeCommand(form, request, response, commMapping.isValidateForm());
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long tempFinal = System.currentTimeMillis();
long dif = (tempFinal - tempInicial);
log.info("Requisição " + ": " + String.format("%02d segundos e %02d milisegundos", dif/60, dif%60));
}
}.start();
}
It’s easy to pass parameters to a Thread or Runnable that you pass to the Thread constructor. Just create a class that implements Runnable or extends Thread and pass the parameters in the constructor. Now as for your test strategy, I can’t tell if you’re on the right track because I understand that each request is already handled by a separate thread in your container Rvlet. And you’re looking to pass the request and answer objects to new threads instead of measuring Servlet’s time... you know what I mean? But I can’t give too much pitaco because I didn’t quite understand the intention.
– Piovezan
(and also because I don’t know much of web programming heheh)
– Piovezan
in case I want to simulate as if there were 5 accesses to the service during the same period and how long it took each of these executions, are already separate requests due to Servlet, but I can not do this simultaneous time simulation
– Stenio Vilar
Got it. What you really want to test are the calls to executeCommand. Then do as you are in @Dudaskank’s reply.
– Piovezan