private class Test{
private final Object somethingThatShouldNotBeNull;
public Test(EventBus eventBus){
eventBus.register(this);
// other stuff happens
this.somethingThatShouldNotBeNull = new Object();
}
@Subscriber
public void onObjectSubscriber (ObjectEvent event) {
// can `somethingThatShouldNotBeNull` be null at this point or does the event bus know to wait for the object to be fully initialized?
}
}--
guava-...@googlegroups.com
Project site: https://github.com/google/guava
This group: http://groups.google.com/group/guava-discuss
This list is for general discussion.
To report an issue: https://github.com/google/guava/issues/new
To get help: http://stackoverflow.com/questions/ask?tags=guava
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/81c2dfcc-e4f3-4e4f-b78a-e960fdf97b9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/0b0ab116-8f22-46a3-aa4f-8f0905750793%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/CAGu0%3DMPx0Oq%3D4wLENhBkWoDLZjLbR9LFs48XjD%2B80Z_VfPp9tQ%40mail.gmail.com.
class TestService extends AbstractIdleService {
@Override
protected void startUp() {
myEventBus.register(this);
}
@Override
protected void shutDown() {
myEventBus.unregister(this);
}
....
You can start the Service with service.startAsync().
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/d6d5bf73-ed8c-4e43-b992-e1f41d9b0dce%40googlegroups.com.
Chris,
The problem is that other threads may fire that event handler before eventBus.register() has returned.
Since that memory is only guaranteed to be frozen and visible to other threads after the constructor is complete a subscriber could see variables that have not been frozen by the thread that registered the object.