I have a webpage with a start/pause button (controlling and xml extractor) which, when clicked, executes the following jquery function:
function start() {
// Posts to the start servlet
$.post("servlets/start", function(data) {
update();
});
}
I have a web.xml file mapping the url ‘servlets/start’ to a HttpServlet named ‘StartServlet.java’. The doPost method of this servlet is supposed to start an xml extractor on a new thread or, if an extractor is already running it should pause it. That is all. The doPost method just calls startExtractor() as shown below.
private void newExtractor() {
ArrayList<URL> urls = null;
try {
String path = this.getServletContext().getRealPath(
"internalLinks.txt");
urls = GlobalUtils.getLinks(path);
extractor = new Extractor(urls);
thread = new Thread(extractor);
fillContextPool(extractor, false);
} catch (IOException e) {
System.out.println("Failed to start");
}
}
private void startExtractor() {
if (thread == null) {
newExtractor();
thread.run();
} else {
extractor.togglePause();
fillContextPool(extractor, stopForced);
}
}
The problem is, that the jquery post does not complete until the extractor does, meaning the button cannot be clicked again until the extractor has finished; essentially making it impossible to actually pause the extractor.
Any ideas as to how to make the post complete as son as the extractor is started and not have to wait until it has finished?
Thanks in advance!
A thread is started using the
start()method. Not therun()method.