Issue #851 change date formatters to use ThreadLocal instead of synchronized blocks.
Change-Id: I1d3818cf90d21d3cc725b9a83e55eb5068b7aa62 Former-commit-id:c2937d7303
[formerlye9f24e8660
] [formerly7c6686f2f4
] [formerlyb1650b6143
[formerly7c6686f2f4
[formerly 181fba1a75357aa39a54267c6df907075f4601dc]]] Former-commit-id:b1650b6143
Former-commit-id: 7e61eb27b9b666aa966565378d537d64b5825d69 [formerly6a3e6f599f
] Former-commit-id:4efd9149f7
This commit is contained in:
parent
5a58fc89bf
commit
701d77f90a
3 changed files with 36 additions and 50 deletions
|
@ -106,12 +106,17 @@ public abstract class AbstractParmManager implements IParmManager {
|
|||
|
||||
private static final int NOTIFICATION_THREADS = 4;
|
||||
|
||||
private static final SimpleDateFormat dateFormat = new SimpleDateFormat(
|
||||
DatabaseID.MODEL_TIME_FORMAT);
|
||||
private static final ThreadLocal<SimpleDateFormat> dateFormat = new ThreadLocal<SimpleDateFormat>() {
|
||||
|
||||
static {
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
SimpleDateFormat df = new SimpleDateFormat(
|
||||
DatabaseID.MODEL_TIME_FORMAT);
|
||||
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
return df;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
protected class ParmIDVis {
|
||||
private ParmID pid;
|
||||
|
@ -478,9 +483,7 @@ public abstract class AbstractParmManager implements IParmManager {
|
|||
if (string.length() - pos == 14) {
|
||||
try {
|
||||
dtg = string.substring(pos + 1);
|
||||
synchronized (dateFormat) {
|
||||
dateFormat.parse(dtg);
|
||||
}
|
||||
dateFormat.get().parse(dtg);
|
||||
} catch (ParseException e) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -59,12 +59,17 @@ public class SmartInitRecordPK implements ISerializableObject, Serializable,
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final SimpleDateFormat dateFormat = new SimpleDateFormat(
|
||||
DatabaseID.MODEL_TIME_FORMAT);
|
||||
private static final ThreadLocal<SimpleDateFormat> dateFormat = new ThreadLocal<SimpleDateFormat>() {
|
||||
|
||||
static {
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
SimpleDateFormat df = new SimpleDateFormat(
|
||||
DatabaseID.MODEL_TIME_FORMAT);
|
||||
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
return df;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public enum State {
|
||||
PENDING, RUNNING
|
||||
|
@ -189,9 +194,7 @@ public class SmartInitRecordPK implements ISerializableObject, Serializable,
|
|||
tmp.append(initName);
|
||||
tmp.append(" ValidTime: ");
|
||||
if (validTime != null) {
|
||||
synchronized (dateFormat) {
|
||||
tmp.append(dateFormat.format(validTime));
|
||||
}
|
||||
tmp.append(dateFormat.get().format(validTime));
|
||||
} else {
|
||||
tmp.append("null");
|
||||
}
|
||||
|
|
|
@ -74,12 +74,17 @@ public class DatabaseID implements Serializable, Comparable<DatabaseID>,
|
|||
|
||||
public static final String MODEL_TIME_FORMAT = "yyyyMMdd_HHmm";
|
||||
|
||||
private static final SimpleDateFormat dateFormat = new SimpleDateFormat(
|
||||
MODEL_TIME_FORMAT);
|
||||
private static final ThreadLocal<SimpleDateFormat> dateFormat = new ThreadLocal<SimpleDateFormat>() {
|
||||
|
||||
static {
|
||||
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
SimpleDateFormat df = new SimpleDateFormat(
|
||||
DatabaseID.MODEL_TIME_FORMAT);
|
||||
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
return df;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/** Denotes what type of database */
|
||||
public enum DataType {
|
||||
|
@ -150,14 +155,8 @@ public class DatabaseID implements Serializable, Comparable<DatabaseID>,
|
|||
*/
|
||||
public DatabaseID(String siteId, DataType format, String dbType,
|
||||
String modelName, Date modelTime) {
|
||||
this.siteId = siteId;
|
||||
this.format = format;
|
||||
this.dbType = dbType;
|
||||
this.modelName = modelName;
|
||||
synchronized (dateFormat) {
|
||||
this.modelTime = dateFormat.format(modelTime);
|
||||
}
|
||||
encodeIdentifier();
|
||||
this(siteId, format, dbType, modelName, dateFormat.get().format(
|
||||
modelTime));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -233,21 +232,6 @@ public class DatabaseID implements Serializable, Comparable<DatabaseID>,
|
|||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename for the database associated with this database ID
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String dbFilename() {
|
||||
// TODO: Is this method necessary?
|
||||
return "";
|
||||
}
|
||||
|
||||
public String dbPathName() {
|
||||
// TODO: Is this method necessary?
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a valid database identifier
|
||||
*
|
||||
|
@ -357,9 +341,7 @@ public class DatabaseID implements Serializable, Comparable<DatabaseID>,
|
|||
return false;
|
||||
}
|
||||
try {
|
||||
synchronized (dateFormat) {
|
||||
dateFormat.parse(dtgString);
|
||||
}
|
||||
dateFormat.get().parse(dtgString);
|
||||
modelTime = dtgString;
|
||||
} catch (ParseException e) {
|
||||
return false;
|
||||
|
@ -497,9 +479,7 @@ public class DatabaseID implements Serializable, Comparable<DatabaseID>,
|
|||
Date date = null;
|
||||
if (modelTime != null && !NO_MODEL_TIME.equalsIgnoreCase(modelTime)) {
|
||||
try {
|
||||
synchronized (dateFormat) {
|
||||
date = dateFormat.parse(this.modelTime);
|
||||
}
|
||||
date = dateFormat.get().parse(this.modelTime);
|
||||
} catch (ParseException e) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue