Skip to content

Commit

Permalink
[HELIX-584] SimpleDateFormat should not be used as singleton due to i…
Browse files Browse the repository at this point in the history
…ts race conditions.
  • Loading branch information
lei-xia committed Apr 27, 2015
1 parent a6610a6 commit a29ac9f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Expand Up @@ -575,7 +575,7 @@ public void invokeRebalance() {
// 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;
Expand Down
Expand Up @@ -343,7 +343,7 @@ public static ScheduleConfig parseScheduleFromConfigMap(Map<String, String> cfg)
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;
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -82,6 +77,13 @@ public ScheduleConfig getScheduleConfig() {
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());
Expand All @@ -94,7 +96,7 @@ public Map<String, String> getResourceConfigMap() throws Exception {
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()) {
Expand Down

0 comments on commit a29ac9f

Please sign in to comment.