[Schmitzm-commits] r1741 - trunk/schmitzm-core/src/main/java/de/schmitzm/lang

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Sep 29 21:55:36 CEST 2011


Author: alfonx
Date: 2011-09-29 21:55:36 +0200 (Thu, 29 Sep 2011)
New Revision: 1741

Added:
   trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ConcurrentDateFormat.java
Log:
Eine Klasse um die thread-unsicherheit von DateFormat performant zu umgehen.

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ConcurrentDateFormat.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ConcurrentDateFormat.java	2011-09-29 19:03:28 UTC (rev 1740)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ConcurrentDateFormat.java	2011-09-29 19:55:36 UTC (rev 1741)
@@ -0,0 +1,38 @@
+package de.schmitzm.lang;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+/**
+ * Liefert auf einem Thread immer die selbe {@link DateFormat} Instanz. Bei neuen Threads werden neue {@link DateFormat}
+ * Instanzen erzeugt.
+ */
+public class ConcurrentDateFormat extends ThreadLocal<DateFormat> {
+
+	private final String dateformat;
+
+	public ConcurrentDateFormat(final String dateformat) {
+		this.dateformat = dateformat;
+	}
+
+	@Override
+	public DateFormat get() {
+		return super.get();
+	}
+
+	@Override
+	protected DateFormat initialValue() {
+		return new SimpleDateFormat(dateformat);
+	}
+
+	@Override
+	public void remove() {
+		super.remove();
+	}
+
+	@Override
+	public void set(DateFormat value) {
+		super.set(value);
+	}
+
+}
\ No newline at end of file


Property changes on: trunk/schmitzm-core/src/main/java/de/schmitzm/lang/ConcurrentDateFormat.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the Schmitzm-commits mailing list