So I'm in a situation where I need to write an intensive operation for part of my company's application, keep it off of the UI thread (we use Swing), and interact with a whole bunch of highly thread-unsafe components. Fun times.
I'm trying to simplify this for myself. So here's how it would go:
1) The data from the thread-unsafe components would only be read, not written to.
2) A reference to that data would be passed to the background thread as shown below:
final Object someData = getSomeData();
Runnable task = new Runnable() {
@Override
public void run() {
doSomething(someData);
}
};
Also, a modal dialog would block the user from inadvertently changing any of the values during this process. So the state of someData would be unchanged during the entire process, it would just be read from.
So, I'm always very paranoid about memory consistency issues. Would there be any here? By passing the reference in this way, would the background thread get the most up-to-date status of it at that point?
Thanks.