multithreading - Long running background thread causes HTTP request to timeout -


i have spring 3.0 webmvc application running on tomcat 7. on application startup kick off background thread load in-memory cache records db. thread typically takes on hour load data db. in same application have @controller annotated class exposes rest interface clients can objects loaded cache.

one of our requirements rest requests made prior data load being finished return service_unavailable (503) http code client immediately. accomplish set simple check of boolean flag each request method in controller makes before doing work. if value false method should return 503 code. loader thread set flag true once completed load allow request methods function normally.

the problem background thread seems causing http requests sent controller timeout after 30 seconds instead of hitting flag , returning 503 code client. i'm not expert in tomcat threading issues , wonder if i'm doing wrong when creating long running background thread? using "implements runnable" method create thread described in this question , starting thread on containing bean initialization. there better way kick off long running background thread inside tomcat doesn't interfere request handling? or there else i'm missing?

if you, few things differently:

  1. see if want use external cache. in past, had success using project voldemort (http://www.project-voldemort.com/voldemort/), there other alternatives.
  2. if externalize cache, then, restart of tomcat not require reloading of cache.
  3. build separate application job load cache.
  4. see if want process request, if entry looking not available in cache, directly looking db.
  5. do not use own threads in application containers tomcat. tomcat has own thread management logic built it, , creating user threads big-no.

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -