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.
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.
What are you doing in the new thread? 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.
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.