Given the J5+ memory model (JSR-133) is the following code thread-safe and permissible?
And if it's safe, is it acceptable in some situations?
public final class BackgroundProcessor
extends Object
implements Runnable
{
public BackgroundProcessor(...) {
super();
...
new Thread(this).start();
}
public void run() {
...
}
}
As I read the new JMM spec, initiating a thread creates a happens-before relationship with anything the initiated thread does.
Assume that the object has private member variables set in the constructor and used in run().
And the class is marked final to prevent sub-classing surprises.
Note: There is a similar question here, but this has a different angle: http://stackoverflow.com/questions/84285/calling-thread-start-within-its-own-constructor