Java http post related question
I have a piece of code that has to instruct my servlet to do some processing. My code does not expect to get anything back from the servlet. Its job is to notify the servlet that servlet needs to do some pr开发者_开发百科ocessing. What needs to be processed, how it needs to be process is part of the URL, for example: http://myserver:port/myservlet/something.do?param1=param1value¶m2=param2value...
But I don't want my code to wait for any response from the servlet. My code should move on. Currently I am seeing that my code makes one request and then waits until the servlet sends a response back before moving onto to making the next http post request. Multithreading is an option but is there any other option other than this?
The call to the servlet is blocking. There isn't much you can do about it, except run the process in a separate thread. For instance:
ExecutorService executor = Executors.newSingleThreadExecutor();
// NON BLOCKING CALL
executor.submit(new Runnable() {
@Override
public void run() {
callTheServlet();
}
});
executor.shutdown();
精彩评论