I have the following pretty simple callback interface and POJO class:
public interface Action{
public void doAction();
}
public class Person{
private String name;
private String address;
}
And I will use it as follows:
public class ActionExecutor{
private static final Logger logger = LogManager.getLogger(ActionExecutor.class);
private final BlockingQueue<Action> blockingQueue = new LinkedBlockingQueue(2000);
public void execute(final Person p){
blockingQueue.put(new Action(){
public void doAction(){
logger.info("Execution started: " +p.toString );
});
}
}
BlockingQueue here it is used to implement the manufacturer-consumer.
Question: Is it guaranteed that the consumer flow taking measures out BlockingQueuewill write the correct journal message? That is, he observes the correct state Person? But I'm not so sure about that.
I think not, this is not guaranteed, because before the order between the changes made by the manufacturer and the reading by the producer does not occur.
source
share