• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Record fetch from DB to html as a stream

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The requirement.
Database containing thousands of records, instead of making the user wait till entire record set is fetched from a data store, the data should be pushed to the browser as and when the record is fetched and immediately rendered on the browser.
What is the best way in JAVA.

My approach.
Task--Create Java Thread 1 -> Hit DB, get the records say 1000 at a time. Iterate through the list, Place every record in messageQueue for reliability of the record and send it to HTML browser through event handler.Once the count is reached, hit DB again and fetch 1000 records.

 
Marshal
Posts: 75720
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you doing in the new thr‍ead? How are you going to ensure that the reading from the file is fast enough that only complete data are sent to the browser? I think you may have a race condition there.
 
dileep keely
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ritchie-
Can you please provide me a hint on what is the best way?
 
Campbell Ritchie
Marshal
Posts: 75720
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you can make the queue thread‑safe, like a blocking queue. That will allow the consumer thread to run happily as long as there is something to consume, then it will wait for the producer thread to refill the queue. Depends which runs faster, the producer or the consumer.
 
Sheriff
Posts: 22650
126
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two ways (that I know of) to properly push data in an ongoing stream from the server to the browser:
1) Use server-sent events
2) Use WebSockets
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic