Repository: helix Updated Branches: refs/heads/master a6610a67e -> a29ac9fb3
[HELIX-584] SimpleDateFormat should not be used as singleton due to its race conditions. Project: http://git-wip-us.apache.org/repos/asf/helix/repo Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/a29ac9fb Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/a29ac9fb Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/a29ac9fb Branch: refs/heads/master Commit: a29ac9fb35365d1fe8cf12ef95c58643a5fea36b Parents: a6610a6 Author: Lei Xia <[email protected]> Authored: Sun Apr 26 17:25:33 2015 -0700 Committer: Lei Xia <[email protected]> Committed: Sun Apr 26 17:25:33 2015 -0700 ---------------------------------------------------------------------- .../main/java/org/apache/helix/task/TaskDriver.java | 2 +- .../src/main/java/org/apache/helix/task/TaskUtil.java | 2 +- .../java/org/apache/helix/task/WorkflowConfig.java | 14 ++++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/helix/blob/a29ac9fb/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java b/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java index 76acc64..f9a6be3 100644 --- a/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java +++ b/helix-core/src/main/java/org/apache/helix/task/TaskDriver.java @@ -575,7 +575,7 @@ public class TaskDriver { // find a task for (String resource : _admin.getResourcesInCluster(_clusterName)) { IdealState is = _admin.getResourceIdealState(_clusterName, resource); - if (is.getStateModelDefRef().equals(TaskConstants.STATE_MODEL_NAME)) { + if (is != null && is.getStateModelDefRef().equals(TaskConstants.STATE_MODEL_NAME)) { HelixDataAccessor accessor = _manager.getHelixDataAccessor(); accessor.updateProperty(accessor.keyBuilder().idealStates(resource), is); break; http://git-wip-us.apache.org/repos/asf/helix/blob/a29ac9fb/helix-core/src/main/java/org/apache/helix/task/TaskUtil.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/task/TaskUtil.java b/helix-core/src/main/java/org/apache/helix/task/TaskUtil.java index ad5770d..cf07751 100644 --- a/helix-core/src/main/java/org/apache/helix/task/TaskUtil.java +++ b/helix-core/src/main/java/org/apache/helix/task/TaskUtil.java @@ -343,7 +343,7 @@ public class TaskUtil { Date startTime = null; if (cfg.containsKey(WorkflowConfig.START_TIME)) { try { - startTime = WorkflowConfig.DEFAULT_DATE_FORMAT.parse(cfg.get(WorkflowConfig.START_TIME)); + startTime = WorkflowConfig.getDefaultDateFormat().parse(cfg.get(WorkflowConfig.START_TIME)); } catch (ParseException e) { LOG.error("Unparseable date " + cfg.get(WorkflowConfig.START_TIME), e); return null; http://git-wip-us.apache.org/repos/asf/helix/blob/a29ac9fb/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java ---------------------------------------------------------------------- diff --git a/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java b/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java index a4d0545..845ba2e 100644 --- a/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java +++ b/helix-core/src/main/java/org/apache/helix/task/WorkflowConfig.java @@ -40,11 +40,6 @@ public class WorkflowConfig { /* Default values */ public static final long DEFAULT_EXPIRY = 24 * 60 * 60 * 1000; - public static final SimpleDateFormat DEFAULT_DATE_FORMAT = new SimpleDateFormat( - "MM-dd-yyyy HH:mm:ss"); - static { - DEFAULT_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); - } /* Member variables */ private final JobDag _jobDag; @@ -82,6 +77,13 @@ public class WorkflowConfig { return _scheduleConfig; } + public static SimpleDateFormat getDefaultDateFormat() { + SimpleDateFormat defaultDateFormat = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss"); + defaultDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + + return defaultDateFormat; + } + public Map<String, String> getResourceConfigMap() throws Exception { Map<String, String> cfgMap = new HashMap<String, String>(); cfgMap.put(WorkflowConfig.DAG, getJobDag().toJson()); @@ -94,7 +96,7 @@ public class WorkflowConfig { if (scheduleConfig != null) { Date startTime = scheduleConfig.getStartTime(); if (startTime != null) { - String formattedTime = WorkflowConfig.DEFAULT_DATE_FORMAT.format(startTime); + String formattedTime = WorkflowConfig.getDefaultDateFormat().format(startTime); cfgMap.put(WorkflowConfig.START_TIME, formattedTime); } if (scheduleConfig.isRecurring()) {
