java - Provide periodically updated image from server without corruption -


task

i have java web server provides access image saved file webcam via opencv / javafx , periodically (e. g. every second) updated.

problem

if image updated on server while it's being delivered client, image on client of course incomplete , gets corrupted.

question

what preferred way guarantee image client reads delivered whole? or @ least image shouldn't corrupted.

i wouldn't mind having e. g. upper image part previous image, lower part new image if solution, how approach this?

you need 2 things this:

  1. you need have control on image creation, hence read image via javafx , store on disk.
  2. you control delivery client. servlet that.

if store image on disk yourself, block delivery client. using reentrantreadwritelock suited that.

you call writelock.lock() method before writing image , writelock.unlock() when finished.

for delivery client use same lock, call readlock.lock()method before sending image client andreadlock.unlock()` when finished.

the servlet pretty simple, return image read stream file read lock in place. lock ensure complete image returned, no corrupted one.

if not store image on disk, gets more tricky. try copy on disk after notified of creation, still subject race condition.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -