multithreading - Multhreading a java rest service -
i'm new java , building java rest service using cxf jaxrs library.
i the service able consume multiple http request @ time. how accomplish this?
do need host service in web container? or can accomplish multithreading if run service without(preferable) web container ?
thanks
you have modify architecture of application process multiple requests @ 1 time , meanwhile save incoming requests future processing.
implement master-worker pattern, solve problem. can follow these steps implement pattern(its approach not algorithm):
1) utilize executor framework of java 5 or fork bring together java 7 per wish. using java 5.
2) utilize shared queue save data(say work object) temporarily future use. have used blockingqueue thread-safe.
3) create master class, start , stop multiple instances(n) of workers. when new request received, master set info in work object , add together work object queue. @ time of adding work object queue, master phone call notifyall method on queue (to awake waiting workers).
4) create worker thread class hear on queue (by giving reference shared queue in constructor). fetch work objects 1 1 queue until queue empty. set worker in wait state while queue empty. when master phone call notifyall method on queue, 1 time again go live.
let me know if need other clarification.
one simple illustration of executor framework(not master worker pattern) here
java multithreading rest
No comments:
Post a Comment