From 8b6824e9b54ad54ffd6df9baecc67cdb33027f78 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Tue, 4 Feb 2014 08:48:36 +0700 Subject: SimpleDateFormat synchronization --- src/java/com/juick/http/www/PageTemplates.java | 49 +++++++++++++++----------- src/java/com/juick/http/www/UserThread.java | 2 +- 2 files changed, 29 insertions(+), 22 deletions(-) (limited to 'src/java/com/juick/http/www') diff --git a/src/java/com/juick/http/www/PageTemplates.java b/src/java/com/juick/http/www/PageTemplates.java index 23f2b007..32e77239 100644 --- a/src/java/com/juick/http/www/PageTemplates.java +++ b/src/java/com/juick/http/www/PageTemplates.java @@ -43,7 +43,7 @@ import ru.sape.Sape; public class PageTemplates { public static Sape sape = null; - private static SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static SimpleDateFormat sdfSimple = new SimpleDateFormat("d MMM"); private static SimpleDateFormat sdfFull = new SimpleDateFormat("d MMM yyyy"); private static SimpleDateFormat sdfJS = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss"); @@ -289,33 +289,40 @@ public class PageTemplates { } return days + " " + unit + " назад"; } else { - try { - Date pDate = sdfSQL.parse(fulldate); - Calendar c = Calendar.getInstance(); - int curyear = c.get(Calendar.YEAR); - c.setTime(pDate); - if (c.get(Calendar.YEAR) == curyear) { - return sdfSimple.format(pDate); - } else { - return sdfFull.format(pDate); + String ret = fulldate; + synchronized (sdfSQL) { + try { + Date pDate = sdfSQL.parse(fulldate); + Calendar c = Calendar.getInstance(); + int curyear = c.get(Calendar.YEAR); + c.setTime(pDate); + if (c.get(Calendar.YEAR) == curyear) { + ret = sdfSimple.format(pDate); + } else { + ret = sdfFull.format(pDate); + } + } catch (Exception e) { + System.err.println("PARSE EXCEPTION: " + fulldate); } - } catch (Exception e) { - return fulldate; } + return ret; } } public static String formatJSLocalTime(String ts) { - try { - Date date = sdfSQL.parse(ts); - return ""; - } catch (Exception e) { - System.err.print(e); + String ret = ""; + synchronized (sdfSQL) { + try { + Date date = sdfSQL.parse(ts); + ret = ""; + } catch (Exception e) { + System.err.println("PARSE EXCEPTION: " + ts); + } } - return ""; + return ret; } public static String formatReplies(int replies) { diff --git a/src/java/com/juick/http/www/UserThread.java b/src/java/com/juick/http/www/UserThread.java index 57c1a696..3357f65c 100644 --- a/src/java/com/juick/http/www/UserThread.java +++ b/src/java/com/juick/http/www/UserThread.java @@ -293,7 +293,7 @@ public class UserThread { int childs = msg.getChildsCount(); if (ReplyTo == 0 && childs > 1 && replies.size() > 10) { - out.println("