提交 a1862621 编写于 作者: N Nicolas De Loof

Do not use two volatiles to hold state that needs to be atomically updated

上级 e0a394ab
......@@ -168,7 +168,6 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
* @see #getEnvironment()
*/
private volatile EnvVars cachedEnvironment;
private volatile boolean environmentCached;
private final WorkspaceList workspaceList = new WorkspaceList();
......@@ -346,7 +345,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
* make much sense because as soon as {@link Computer} is connected it can be disconnected by some other threads.)
*/
public final Future<?> connect(boolean forceReconnect) {
environmentCached = false;
this.cachedEnvironment = null;
connectTime = System.currentTimeMillis();
return _connect(forceReconnect);
}
......@@ -947,12 +946,13 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
* If this is the master, it returns the system property of the master computer.
*/
public EnvVars getEnvironment() throws IOException, InterruptedException {
if (environmentCached) {
EnvVars cachedEnvironment = this.cachedEnvironment;
if (cachedEnvironment != null) {
return cachedEnvironment;
}
cachedEnvironment = EnvVars.getRemote(getChannel());
environmentCached = true;
this.cachedEnvironment = cachedEnvironment;
return cachedEnvironment;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册