I have a Rest service call for chain of responsibility, for the better performance we have added multi threading but unable to handle the exception Please find the code sample: Starting with Rest Service method
@POST
@Path("/dispatch")
public Response dispatchEvent(){
Thread steps = new Thread(new HandlerExecutor());
steps.start();
}
HandlerExecutor.java
public class HandlerExecutor implements Runnable {
@Override
public void run() {
Handler first = HandlerLocator.getHandler();
if (first != null) {
first.process();
}
}
}
HandlerLocator.java
public class HandlerLocator {
public static Map<String, List<Handler>> allHandlers = null;
public static Handler getHandler() {
Handler first = null;
List<Handler>> h = new HashMap<String, List<Handler>>();
List<Handler> list = new ArrayList<Handler>();
list.add(new ConsoleHandler());
list.add(new FileHandler());
list.add(new FinalHandler());
h.put("1", list);
List<Handler> clientHandlers = h.get("1");
if (clientHandlers != null) {
int size = clientHandlers.size();
Handler h1, prev = null;
for (int i = 0; i < size; i++) {
h1 = (Handler) clientHandlers.get(i);
if (first == null) {
first = h1;
} else {
prev.setNext(h1);
}
prev = h1;
}
}
return first;
}
}
Handler.java
public interface Handler extends Serializable {
Handler setNext(Handler next);
void process();
}
BasicHandler.java
Aucun commentaire:
Enregistrer un commentaire