less locking in time format computation, caching and during secondary (remote) search evaluation

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7106 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent 9c0c94683c
commit e8228fba09

@ -388,7 +388,7 @@ public final class SearchEvent {
if (oldAbstract == null) { if (oldAbstract == null) {
// new abstracts in the cache // new abstracts in the cache
abstractsCache.put(wordhash, singleAbstract); abstractsCache.put(wordhash, singleAbstract);
} else { } else synchronized (oldAbstract) {
// extend the abstracts in the cache: join the single abstracts // extend the abstracts in the cache: join the single abstracts
for (Map.Entry<String, String> oneref: singleAbstract.entrySet()) { for (Map.Entry<String, String> oneref: singleAbstract.entrySet()) {
String urlhash = oneref.getKey(); String urlhash = oneref.getKey();

@ -65,15 +65,15 @@ abstract class SimpleARC<K, V> extends AbstractMap<K, V> implements Map<K, V>, I
* @param v * @param v
*/ */
public final synchronized V put(final K s, final V v) { public final synchronized V put(final K s, final V v) {
V r = null;
if (this.levelB.containsKey(s)) { if (this.levelB.containsKey(s)) {
r = this.levelB.put(s, v); V r = this.levelB.put(s, v);
assert (this.levelB.size() <= cacheSize); // the cache should shrink automatically assert (this.levelB.size() <= cacheSize); // the cache should shrink automatically
return r;
} else { } else {
r = this.levelA.put(s, v); V r = this.levelA.put(s, v);
assert (this.levelA.size() <= cacheSize); // the cache should shrink automatically assert (this.levelA.size() <= cacheSize); // the cache should shrink automatically
return r;
} }
return r;
} }
/** /**

@ -100,9 +100,14 @@ public final class DateFormatter {
* @param date The Date instance to transform. * @param date The Date instance to transform.
* @return A fixed width (20 chars) ISO8601 date String. * @return A fixed width (20 chars) ISO8601 date String.
*/ */
private static long FORMAT_ISO8601_last_time = 0;
private static String FORMAT_ISO8601_last_format = "";
public static final String formatISO8601(final Date date) { public static final String formatISO8601(final Date date) {
if (date == null) return ""; if (date == null) return "";
return format(FORMAT_ISO8601, date); if (Math.abs(date.getTime() - FORMAT_ISO8601_last_time) < 1000) return FORMAT_ISO8601_last_format;
FORMAT_ISO8601_last_format = format(FORMAT_ISO8601, date);
FORMAT_ISO8601_last_time = date.getTime();
return FORMAT_ISO8601_last_format;
} }
public static final String formatANSIC(final Date date) { public static final String formatANSIC(final Date date) {
if (date == null) return ""; if (date == null) return "";
@ -114,6 +119,48 @@ public final class DateFormatter {
return FORMAT_RFC1123_SHORT.format(date); return FORMAT_RFC1123_SHORT.format(date);
} }
/**
* Identical to {@link #formatShortDay(Date)}, but for short second format.
*/
private static long FORMAT_SHORT_SECOND_last_time = 0;
private static String FORMAT_SHORT_SECOND_last_format = "";
public static String formatShortSecond(final Date date) {
if (date == null) return "";
if (Math.abs(date.getTime() - FORMAT_SHORT_SECOND_last_time) < 1000) return FORMAT_SHORT_SECOND_last_format;
FORMAT_SHORT_SECOND_last_format = format(FORMAT_SHORT_SECOND, date);
FORMAT_SHORT_SECOND_last_time = date.getTime();
return FORMAT_SHORT_SECOND_last_format;
}
public static String formatShortMilliSecond(final Date date) {
return format(FORMAT_SHORT_MILSEC, date);
}
/**
* Note: The short day format doesn't include any timezone information. This method
* transforms the date into the GMT/UTC timezone. Example: If the local system time is,
* 2007-12-18 01:15:00 +0200, then the resulting String will be "2007-12-17".
* In case you need a format with a timezon offset, use {@link #formatShortDay(TimeZone)}
* @return a String representation of the current system date in GMT using the
* short day format, e.g. "20071218".
*/
public static String formatShortDay() {
return format(FORMAT_SHORT_DAY, new Date());
}
/**
* @see #formatShortDay()
* @param date the Date to transform
*/
private static long FORMAT_SHORT_DAY_last_time = 0;
private static String FORMAT_SHORT_DAY_last_format = "";
public static String formatShortDay(final Date date) {
if (date == null) return "";
if (Math.abs(date.getTime() - FORMAT_SHORT_DAY_last_time) < 1000) return FORMAT_SHORT_DAY_last_format;
FORMAT_SHORT_DAY_last_format = format(FORMAT_SHORT_DAY, date);
FORMAT_SHORT_DAY_last_time = date.getTime();
return FORMAT_SHORT_DAY_last_format;
}
/** /**
* Parse dates as defined in {@linkplain http://www.w3.org/TR/NOTE-datetime}. * Parse dates as defined in {@linkplain http://www.w3.org/TR/NOTE-datetime}.
@ -236,38 +283,6 @@ public final class DateFormatter {
return d; return d;
} }
/**
* Note: The short day format doesn't include any timezone information. This method
* transforms the date into the GMT/UTC timezone. Example: If the local system time is,
* 2007-12-18 01:15:00 +0200, then the resulting String will be "2007-12-17".
* In case you need a format with a timezon offset, use {@link #formatShortDay(TimeZone)}
* @return a String representation of the current system date in GMT using the
* short day format, e.g. "20071218".
*/
public static String formatShortDay() {
return format(FORMAT_SHORT_DAY, new Date());
}
/**
* @see #formatShortDay()
* @param date the Date to transform
*/
public static String formatShortDay(final Date date) {
return format(FORMAT_SHORT_DAY, date);
}
/**
* This should only be used, if you need a short date String that needs to be aligned to
* a special timezone other than GMT/UTC. Be aware that a receiver won't be able to
* recreate the original Date without additional timezone information.
* @see #formatShortDay()
* @param date the Date to transform
* @param tz a TimeZone the resulting date String should be aligned to.
*/
public static String formatShortDay(final Date date, final TimeZone tz) {
return format(FORMAT_SHORT_DAY, date, tz);
}
/** /**
* Parse a String representation of a Date in short day format assuming the date * Parse a String representation of a Date in short day format assuming the date
* is aligned to the GMT/UTC timezone. An example for such a date string is "20071218". * is aligned to the GMT/UTC timezone. An example for such a date string is "20071218".
@ -288,25 +303,6 @@ public final class DateFormatter {
return formatShortSecond(new Date()); return formatShortSecond(new Date());
} }
/**
* Identical to {@link #formatShortDay(Date)}, but for short second format.
*/
public static String formatShortSecond(final Date date) {
return format(FORMAT_SHORT_SECOND, date);
}
public static String formatShortMilliSecond(final Date date) {
return format(FORMAT_SHORT_MILSEC, date);
}
/**
* Identical to {@link #formatShortDay(Date, TimeZone)}, but for short second format.
*/
public static String formatShortSecond(final Date date, final TimeZone tz) {
return format(FORMAT_SHORT_SECOND, date, tz);
}
//TODO check the following 2 parse methods for correct use (GMT vs. different timezone) //TODO check the following 2 parse methods for correct use (GMT vs. different timezone)
/** /**
* Like {@link #parseShortDay(String)}, but for the "short second" format which is short date * Like {@link #parseShortDay(String)}, but for the "short second" format which is short date
@ -370,20 +366,6 @@ public final class DateFormatter {
} }
} }
/** called by all public format...(..., TimeZone) methods */
private static String format(final SimpleDateFormat format, final Date date, final TimeZone tz) {
String result;
synchronized (format) {
final TimeZone bakTZ = format.getTimeZone();
format.setTimeZone(tz == null ? TZ_GMT : tz);
result = format.format(date);
format.setTimeZone(bakTZ);
}
return result;
}
/** called by all public format...(...) methods */ /** called by all public format...(...) methods */
private static String format(final SimpleDateFormat format, final Date date) { private static String format(final SimpleDateFormat format, final Date date) {
synchronized (format) { synchronized (format) {

Loading…
Cancel
Save