Merge "Issue #851 change date formatters to use ThreadLocal instead of synchronized blocks." into development
Former-commit-id:8631b64e75
[formerly97a1d083cd
[formerly 4b7c1b1876f07de56c8f915d7c4a9c7707ccdf13]] Former-commit-id:97a1d083cd
Former-commit-id:4f64038c78
This commit is contained in:
commit
0ee07efae3
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