update MainHttpHandler.java
fix bugs which could cause inconsistent states of objects of this type