java - Simultaneously processing in one Servlet -


I have a service that receives a request, to get 5 tasks (hold the external data form) and return all data Order the client.

After completing all 5 tasks, how to process 5 tasks together and continue the servlet code?

You can use a synchronization help

Allows one or more threads to wait until the set of operations to be completed in the second thread.

Sample code:

  count initial start signal = new calculation log (1); Countdown is signed = new MozillaLock (5); // 5 working class worker Runnabal {personal finals countdown start.signal; Private Final Getsdown Latched Sainle; Private final interval form number; / / You can also pass the extra logic along with the worker (CountdownLunch StartSignal, countdownloaded, sign, int threshold) {this.startSignal = startSignal; This.doneSignal = doneSignal; This.threadNumber = threadNumber; } Run Public Zero () {try.signal.await (). do your work(); // Actual work is done to be done here Signal countdown (); } Grip (Prerupted Pre-Probe) {LOGGER.error (ex); }}} 5 have been started for 5 new threads (Int i = 1; i & lt; = 5; i ++) (new thread (new worker, started, signal, I)) } StartSignal.countDown (); // Try to proceed to all threads {doneSignal.await (); // Wait for all to finish / all 5 tasks are finished and do whatever you want to do} Grip (interrupted) option interrupted exception {LOGGER.error (interruptedException); }  

and


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -