[vlma-devel] commit: DateFormat is not thread safe, don't store it in a static field. ( Adrien Grand )

git version control git at videolan.org
Sat Feb 14 21:38:06 CET 2009


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sat Feb 14 21:09:47 2009 +0100| [7a0a3a11a0521c6e27e5c13ce644bbb97bd8bd82] | committer: Adrien Grand 

DateFormat is not thread safe, don't store it in a static field.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=7a0a3a11a0521c6e27e5c13ce644bbb97bd8bd82
---

 .../controller/server/ServerViewController.java    |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/vlma-webapp/src/main/java/org/videolan/vlma/web/controller/server/ServerViewController.java b/vlma-webapp/src/main/java/org/videolan/vlma/web/controller/server/ServerViewController.java
index 7469ce6..5d8c111 100644
--- a/vlma-webapp/src/main/java/org/videolan/vlma/web/controller/server/ServerViewController.java
+++ b/vlma-webapp/src/main/java/org/videolan/vlma/web/controller/server/ServerViewController.java
@@ -21,7 +21,6 @@
 package org.videolan.vlma.web.controller.server;
 
 import java.io.IOException;
-import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
@@ -86,7 +85,7 @@ public class ServerViewController implements Controller {
     public static class TimeSpan {
 
         private long millis;
-        private static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
+        private static final String TIME_FORMAT = "HH:mm:ss";
 
         public TimeSpan(long millis) {
             this.millis = millis;
@@ -99,7 +98,9 @@ public class ServerViewController implements Controller {
         public String getHours() {
             long hoursMillis = millis % (1000 * 60 * 60 * 24);
             Date date = new Date(hoursMillis);
-            return dateFormat.format(date);
+            // Don't store the dateformat in a static field because
+            // DateFormat is not thread safe
+            return new SimpleDateFormat(TIME_FORMAT).format(date);
         }
     }
 



More information about the vlma-devel mailing list