Skip to content

Commit

Permalink
Make parsing exercise deadlines thread safe
Browse files Browse the repository at this point in the history
Exercise#getDeadlineDate was randomly failing because SimpleDateFormat
is not thread safe.
  • Loading branch information
nygrenh committed Oct 14, 2016
1 parent 233303c commit 6f85e5e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/fi/helsinki/cs/tmc/core/domain/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
public class Exercise implements Serializable {

private static final Logger logger = LoggerFactory.getLogger(Exercise.class);
private static final DateFormat DATE_FORMAT =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSX";

private int id;
private String name;
Expand Down Expand Up @@ -138,8 +137,9 @@ public Date getDeadlineDate() {
if (Strings.isNullOrEmpty(this.getDeadline())) {
return null;
}
final SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT);
try {
return DATE_FORMAT.parse(this.getDeadline());
return dateFormatter.parse(this.getDeadline());
} catch (ParseException ex) {
logger.warn("Failed to parse date {}", this.getDeadline(), ex);
return null;
Expand Down

0 comments on commit 6f85e5e

Please sign in to comment.