Massive Boisson wrote:
1. Now it opens a new thread for every incomming request? --> (Yes it opens new thread for every incomming request)
Yes, every incoming request spawns a new thread in WebServer.
2. But does it use one instance of myHandler, or does it create new instance of myHandler for every request? --> (It creates new instance of myHandler for every request)
No, I believe that only one instance of the class used as a handler is instantiated. That is:
server.addHandler("some.name", new MyHandler());
will only create one MyHandler object and keep it around for incoming requests, not one seperate instance for each incoming request. (Can someone verify this?)
This obviously has some implications on threading, since potentially multiple threads can have the same handler object at any given time. Local class variables of MyHandler would need to be synchronized, created as a ThreadLocal, or some other technique if you need to write to them. Otherwise you risk having another thread (ie. another incoming request) change the state of your handler unexpectedly.