I've a very odd behaviour on one of my class, and don't know exactly what is happening.
1) I've a JSP which sends a request to a Servlet with AJAX 2) The servlet process this request in the following way: - It makes a reflection of a class, and then call a method (which is supplied as a parameter from the JSP), it then output the result of the method back to the Ajax.
So here are the original problem, and then the partial solution I came up with:
The call to the method was being done several times, but I don't know why. The JSP-Ajax only call it ONCE (tested many times), but the servlet was like "reloading itself" and calling the method several times, thus, causing errors in the process. Since I couldn't find what was going on with the servlet, I made the "reflected" method synchronized, so no matter how many times it got requested, one request will finish and then the other, and so on. I put a couple of messages to the output, writing when the method was accessed and when it finished the job.
But... the message that signals it's been accessed, is written several times before the end message is thrown... so I don't understand, maybe synchronization doesn't work well with reflection? What am I missing, why the method is accessed several times before it finishes? Simply don't get it. Can you help me?
Also, is you have any ideas for the original issue (servlet like "reloading" itself)? In this problem I'm thinking that maybe a header is sent that makes the servlet to reload, but don't know for sure.
EDIT:
Actually I'm doing an instance. This is my servlet code:
Class clase = Class.forName("com.cargaporinterfase.CargaPorInterfase_"+cd_matriz);
Object obj = clase.newInstance();
Method met = clase.getDeclaredMethod(metodo, new Class[]{String.class, String.class});
Ant the method being called is:
public synchronized String procesar(String url,String nu_spid) throws CargaPorInterfaseException{
//... more processing
}