Java rest api that needs to wait before processing -


i have java rest api used iot devices send data. each device has time period (say 15 seconds) communicate api. within time period there can more 1 message same set of data.

what want is, when api receive new message device, wait till end of time period , collect messages received. , process messages when time period over.

what should use collect , process messages given time period?

thanks.

edit using spring boot.

you should try using asyncronous endpoint call syncronous rest. can define after timeout reached.

for example, in spring boot return callable , use taskexecutor:

@controller public class mycontroller {      @requestmapping("/endpoint")      public @responsebody webasynctask<string> handlerequest (httpservletrequest request) {          callable<string> callable = () -> {             return "callable";         };          concurrenttaskexecutor taskexecutor = new concurrenttaskexecutor(executors.newfixedthreadpool(1));          return new webasynctask<>(15000l, taskexecutor, callable);      } } 

you need add configuration in spring task executor thread pool:

@springbootapplication public class asyncconfigexample {      @bean     webmvcconfigurer configurer(){         return new webmvcconfigureradapter(){             @override             public void configureasyncsupport (asyncsupportconfigurer configurer) {                 threadpooltaskexecutor t = new threadpooltaskexecutor();                 t.setcorepoolsize(10);                 t.setmaxpoolsize(100);                 t.setqueuecapacity(50);                 t.setallowcorethreadtimeout(true);                 t.setkeepaliveseconds(120);                 t.initialize();                 configurer.settaskexecutor(t);             }         };     }  } 

here more read:


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -