1

I am trying to figure out how to save my server state by sending it to a JGroups cluster whenever there is an update.

For this purpose I am using the following while loop in my Server's main:

    while (true) {
            if (updated) {
                continue;
            } else {
                updateState(auctions);
            }
        }

And the function that I use to send the data to my cluster:

public static void updateState(ArrayList<Auction> auctions) throws Exception {
        Message message = new Message(null, null, auctions);
        channel.send(message);
        updated = true;
    }

I also use a setter for updated that changes it to false whenever there is a change on my main array list.

Server wouldn't enter the else condition even if updated == false, unless I replace continue; with a random System.out.println(). I find it really strange. Any idea why would this happen?

MIT27
  • 23
  • 3
  • I think that this question has insufficient context; you're not showing the receiver. The busy loop is generally a bad idea and I bet that 'updated' is not even volatile so compiler is optimizing that out. – Radim Vansa Dec 13 '21 at 07:56
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 17 '21 at 23:54

0 Answers0