servlets - How to execute code after response in JavaEE -


i tried, unsuccessfully, find way run code after response.

in case, server sends me data in order let me job action can long (send sms 5000 contacts , check received it, example). server expects http 204 no content response sure data has been received. webapp performs action , send status on rest api.

my problem is: how send response , execute code ?

for tried:

  • dofilter
  • asynccontext
  • executorservice

in each case, in order test if connection closing before end of action, call external url takes 10s on purpose answer. each time, server takes 10s answer.

my servlet hanging on, waiting end of code.

i unable make code works executors (new this), if got error during execution of thread, want send http 204 , handle error on hand.

is there easy way ?

i use background threads poll queue tables things don't have done before response sent , take longer 0.1 seconds. example, email sender thread handles sending emails in response user's action, "thanks order" message. in case servlet generates email , appends record email table status of "ready send", lets email sender thread know there's new email ready sent. email sender thread grabs next oldest "ready send" message, sends it, updates table , waits next one. cool part sending email main program easy appending record table , moving on without mucking smtp service each time. have separate similar thread sending sms. if background process isn't able handle load , starts fall behind, it's pretty easy launch more 1 long you're careful making sure don't try grab same record in queue.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -