I am developing an application in JSF 2.0 and I would like to have a multi-line text box that displays the output that is read (in turn) from a file in real time.
Thus, the goal is to have a page with a button that launches a backend to start reading from a file, and then display the results when reading in a text box.
I thought of it as follows:
Ask the local page to keep track of which lines it received / displayed in the text box.
Periodically, the local page will poll the backend using AJAX and request any new data that has been read (tell which lines on this page so far and only retrieve new lines since then).
This will continue until the entire file is completely restored.
The problem is that the bean method that reads from the file starts the while loop, which blocks. Therefore, to read from the data structure that she writes, at the same time, additional streams will be required, right? I heard that the emergence of new threads in a web application is a potentially dangerous move and that thread pools should be used, etc.
Can anyone shed some light on this?
Update: I tried a couple of different things with no luck. But I managed to get it working by creating a separate Thread to start my lock cycle, while the main thread could be used to read from it whenever an AJAX request is processed. Is there a good library that I could use to do something similar to this that still gives the JSF some lifecycle control over this Thread ?
source share