I've got the following pretty straightforward callback interface and a POJO class:
public interface Action{
public void doAction();
}
public class Person{
private String name;
private String address;
//...etc
//GET, SET, toString
}
And I'm going to 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){
//modify state of p in some way
blockingQueue.put(new Action(){
public void doAction(){
logger.info("Execution started: " +p.toString );
//do some other job
});
}
}
BlockingQueue
here is used to implement producer-consumer.
Question: Is it guaranteed that a consumer thread taking action from the BlockingQueue
will write a correct log message? I.e. it observes a correct state of Person
? But I'm not strictly sure about that.
I think no, it's not guaranteed, as there's no happens before order between modifications made bya producer and reading by a producer.