java - spawning new thread in spring controller -


so in following code, when yservice.performaction() many items , taking time.

i have been advised try use threads make faster went online , looked , found it's not advisable spawn new child threads controller might mess java ee container thread pool. if yservice.performaction() taking time run , need make fast, options have?

many people have been suggesting use quartz spawn new threads. not sure if want complex. how can run specific service in separate threads? there simple way it?

@controller @requestmapping("/test") public class testcontroller { private static final logger logger = logger.getlogger(testcontroller.class);  @autowired xservice xservice; @autowired private yservice yservice;  @requestmapping(method = { requestmethod.get }) public void testcheck(httpservletrequest request, httpservletresponse response) throws ioexception {      try {         list<sl> somelist = xservice.getallx();          stringbuffer status = new stringbuffer("success\n\n");          (sl sl : somelist) {             boolean flag = false;             try {                 flag = yservice.performaction(sl);             } catch (exception e) {                 logger.error(e.getmessage(), e);             }          }          response.setstatus(httpservletresponse.sc_ok);         response.getwriter().write(status.tostring());      } catch (exception e) {         logger.error(e.getmessage(), e);         response.getwriter().write("failed");     } } 

}

your best option use executorservice , call invokeall(). can retrieve instance calling executors.newfixedthreadpool().


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -