Method to check three objects at a time

1

Work with Java and JSF. I have a list of 27 objects and I have a method called every 20 seconds through polling , which updates a field of these objects.

For very specific reasons, I need this method to update every three objects.

That is, update three objects, quit the method and the next time the polling call method, it should update the following three objects.

Is this possible?

    
asked by anonymous 09.08.2016 / 17:22

1 answer

0

You will need to put in some managed bean annotated with PageScoped or SessionScoped , a variable of type int (let's call it indice ) that counts from which object should start the scan.

The method that checks (which is also in this managed bean ) accesses the list of objects, gets the three pertinent objects, and makes a indice += 3; . It is also important to put at least a if somewhere in this method to make sure that you are not trying to access the list beyond the limits, which is important in case the list is finished or has less than three objects remaining.

When all objects have been scanned, you can make a indice = 0; to start the process again. Or do some other action that you deem pertinent.

Keep an eye out for the case where some element is inserted or deleted from the list (assuming there is some case like this), otherwise it could mess with your check.

    
09.08.2016 / 17:27