• Post Reply Bookmark Topic Watch Topic
  • New Topic

Record fetch from DB to html as a stream  RSS feed

 
dileep keely
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • 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.

 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Ritchie-
Can you please provide me a hint on what is the best way?
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!