From 14cb185c17f78269b481986f047a1432844859bf Mon Sep 17 00:00:00 2001 From: Timo Tiuraniemi Date: Tue, 15 Aug 2017 15:07:34 +0300 Subject: [PATCH] Fix for SQL SELECT being issued even though nflow.autostart=false. --- .../io/nflow/engine/internal/dao/ExecutorDao.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nflow-engine/src/main/java/io/nflow/engine/internal/dao/ExecutorDao.java b/nflow-engine/src/main/java/io/nflow/engine/internal/dao/ExecutorDao.java index 8f7a7e632..9439e2621 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/internal/dao/ExecutorDao.java +++ b/nflow-engine/src/main/java/io/nflow/engine/internal/dao/ExecutorDao.java @@ -17,7 +17,6 @@ import java.sql.SQLException; import java.util.List; -import javax.annotation.PostConstruct; import javax.inject.Inject; import org.joda.time.DateTime; @@ -55,7 +54,7 @@ public class ExecutorDao { String executorGroupCondition; int timeoutSeconds; int executorId = -1; - int hostMaxLength; + int hostMaxLength = -1; @Inject public void setEnvironment(Environment env) { @@ -75,9 +74,11 @@ public void setJdbcTemplate(@NFlow JdbcTemplate nflowJdbcTemplate) { this.jdbc = nflowJdbcTemplate; } - @PostConstruct - public void findHostMaxLength() { - hostMaxLength = jdbc.query("select host from nflow_executor where 1 = 0", firstColumnLengthExtractor); + private int getHostMaxLength() { + if (hostMaxLength == -1) { + hostMaxLength = jdbc.query("select host from nflow_executor where 1 = 0", firstColumnLengthExtractor); + } + return hostMaxLength; } private static String createWhereCondition(String group) { @@ -123,7 +124,7 @@ private int allocateExecutorId() { final String host; final int pid; try { - host = left(getLocalHost().getCanonicalHostName(), hostMaxLength); + host = left(getLocalHost().getCanonicalHostName(), getHostMaxLength()); pid = Integer.parseInt(ManagementFactory.getRuntimeMXBean().getName().split("@")[0]); } catch (UnknownHostException | NumberFormatException ex) { throw new RuntimeException("Failed to obtain host name and pid of running jvm", ex);