My application is to use nanoHTTPD as an alternative to pressing buttons and keying in text on an Android UI for automation and regression test I currently have a main UI thread and a customized nanoHTTPD running in a different thread. Consider each HTTP request will be serviced very quickly in the UI thread. I think my model could be simplified if I could force nanoHTTPD to NOT start a new thread for each incoming request. I would not mind the blocking I/O model at all for my use cases. I see there is a pluggable strategy for threading. Can the below be modified such that only one web request is active at a time (blocking model)?
public static class DefaultAsyncRunner implements AsyncRunner {
private long requestCount;
@Override
public void exec(Runnable code) {
++requestCount;
Thread t = new Thread(code);
t.setDaemon(true);
t.setName("NanoHttpd Request Processor (#" + requestCount + ")");
t.start();
}
}
I could probably also do more elaborate message queues but "dumbing-down" to nanoHTTPD in one thread seems simplest.