Created
July 10, 2015 07:55
-
-
Save Kotlin-Native/10f8d393be1d81d86a9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Das Attribut 'format' wird als 'ThreadLocal' definiert: | |
| private static ThreadLocal<SimpleDateFormat> format = new ThreadLocal<SimpleDateFormat>(); | |
| // Beim ersten Zugriff innerhalb eines Threads wird das Objekt initialisiert | |
| private SimpleDateFormat getFormat() { | |
| if (format.get() == null) { | |
| format.set(new SimpleDateFormat("yyyy-MM-dd")); | |
| } | |
| return format.get(); | |
| } | |
| @Override | |
| public XMLGregorianCalendar unmarshal(String value) throws Exception { | |
| ... | |
| // Hier wird die 'ThreadLocal' Instanz verwendet | |
| Date date = getFormat().parse(value); | |
| GregorianCalendar calendar = new GregorianCalendar(); | |
| calendar.setTime(date); | |
| return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar); | |
| ... | |
| } | |
| @Override | |
| public String marshal(XMLGregorianCalendar value) throws Exception { | |
| // Hier wird die 'ThreadLocal' Instanz verwendet | |
| return getFormat().format(value.toGregorianCalendar().getTime()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment