Skip to content

Commit

Permalink
[tensorflow] Revert InstanceHolder for TensorFlow engine (#2884)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu authored Dec 4, 2023
1 parent 2fc8058 commit 586bb07
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
/** {@code TfEngineProvider} is the TensorFlow implementation of {@link EngineProvider}. */
public class TfEngineProvider implements EngineProvider {

private static volatile Engine engine; // NOPMD

/** {@inheritDoc} */
@Override
public String getEngineName() {
Expand All @@ -33,10 +35,13 @@ public int getEngineRank() {
/** {@inheritDoc} */
@Override
public Engine getEngine() {
return InstanceHolder.INSTANCE;
}

private static class InstanceHolder {
static final Engine INSTANCE = TfEngine.newInstance();
if (engine == null) {
synchronized (TfEngineProvider.class) {
if (engine == null) {
engine = TfEngine.newInstance();
}
}
}
return engine;
}
}

0 comments on commit 586bb07

Please sign in to comment.