mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-19 00:01:41 +02:00
Some enhancements to time management:
- remove unnecessary generation of Calendar and Date objects - synchronized SimpleDateFormat objects in blog-, message- and wikiBoard - correct use of TimeZones and SimpleDateFormats git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4288 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
parent
52dd015218
commit
4748d5c1ab
|
@ -51,7 +51,6 @@ import java.text.ParseException;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
@ -77,9 +76,12 @@ public class blogBoardComments {
|
|||
private static final String dateFormat = "yyyyMMddHHmmss";
|
||||
private static final int recordSize = 512;
|
||||
|
||||
private static TimeZone GMTTimeZone = TimeZone.getTimeZone("PST");
|
||||
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat(dateFormat);
|
||||
|
||||
static {
|
||||
SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
|
||||
private kelondroMapObjects datbase = null;
|
||||
|
||||
public blogBoardComments(File actpath, long preloadTime) {
|
||||
|
@ -98,7 +100,9 @@ public class blogBoardComments {
|
|||
}
|
||||
|
||||
private static String dateString(Date date) {
|
||||
return SimpleFormatter.format(date);
|
||||
synchronized (SimpleFormatter) {
|
||||
return SimpleFormatter.format(date);
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalize(String key) {
|
||||
|
@ -132,7 +136,7 @@ public class blogBoardComments {
|
|||
record = new HashMap();
|
||||
key = nkey;
|
||||
if (key.length() > keyLength) key = key.substring(0, keyLength);
|
||||
if(date == null) date = new GregorianCalendar(GMTTimeZone).getTime();
|
||||
if(date == null) date = new Date();
|
||||
record.put("date", dateString(date));
|
||||
if (subject == null) record.put("subject","");
|
||||
else record.put("subject", kelondroBase64Order.enhancedCoder.encode(subject));
|
||||
|
@ -169,10 +173,12 @@ public class blogBoardComments {
|
|||
try {
|
||||
String c = (String) record.get("date");
|
||||
if (c == null) {
|
||||
System.out.println("DEBUG - ERROR: date field missing in blogBoard");
|
||||
return new Date();
|
||||
}
|
||||
return SimpleFormatter.parse(c);
|
||||
System.out.println("DEBUG - ERROR: date field missing in blogBoard");
|
||||
return new Date();
|
||||
}
|
||||
synchronized (SimpleFormatter) {
|
||||
return SimpleFormatter.parse(c);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
return new Date();
|
||||
}
|
||||
|
@ -240,7 +246,7 @@ public class blogBoardComments {
|
|||
key = normalize(key);
|
||||
if (key.length() > keyLength) key = key.substring(0, keyLength);
|
||||
Map record = base.getMap(key);
|
||||
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new GregorianCalendar(GMTTimeZone).getTime(), "".getBytes());
|
||||
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new Date(), "".getBytes());
|
||||
return new CommentEntry(key, record);
|
||||
}
|
||||
|
||||
|
@ -253,7 +259,7 @@ public class blogBoardComments {
|
|||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new GregorianCalendar(GMTTimeZone).getTime(), "".getBytes());
|
||||
if (record == null) return newEntry(key, "".getBytes(), "anonymous".getBytes(), "127.0.0.1", new Date(), "".getBytes());
|
||||
return new CommentEntry(key, record.record);
|
||||
}*/
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ import java.io.IOException;
|
|||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
@ -62,9 +61,12 @@ public class messageBoard {
|
|||
private static final String dateFormat = "yyyyMMddHHmmss";
|
||||
private static final int recordSize = 512;
|
||||
|
||||
private static TimeZone GMTTimeZone = TimeZone.getTimeZone("PST");
|
||||
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat(dateFormat);
|
||||
|
||||
static {
|
||||
SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
|
||||
private kelondroMapObjects database = null;
|
||||
private int sn = 0;
|
||||
|
||||
|
@ -85,7 +87,9 @@ public class messageBoard {
|
|||
}
|
||||
|
||||
private static String dateString() {
|
||||
return SimpleFormatter.format(new GregorianCalendar(GMTTimeZone).getTime());
|
||||
synchronized (SimpleFormatter) {
|
||||
return SimpleFormatter.format(new Date());
|
||||
}
|
||||
}
|
||||
|
||||
private String snString() {
|
||||
|
@ -143,7 +147,9 @@ public class messageBoard {
|
|||
try {
|
||||
String c = key.substring(categoryLength);
|
||||
c = c.substring(0, c.length() - 2);
|
||||
return SimpleFormatter.parse(c);
|
||||
synchronized (SimpleFormatter) {
|
||||
return SimpleFormatter.parse(c);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
return new Date();
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ import java.io.IOException;
|
|||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
@ -62,9 +61,12 @@ public class wikiBoard {
|
|||
private static final String dateFormat = "yyyyMMddHHmmss";
|
||||
private static final int recordSize = 512;
|
||||
|
||||
private static TimeZone GMTTimeZone = TimeZone.getTimeZone("PST");
|
||||
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat(dateFormat);
|
||||
|
||||
static {
|
||||
SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
|
||||
private kelondroMapObjects datbase = null;
|
||||
private kelondroMapObjects bkpbase = null;
|
||||
private static HashMap authors = new HashMap();
|
||||
|
@ -94,11 +96,13 @@ public class wikiBoard {
|
|||
}
|
||||
|
||||
private static String dateString() {
|
||||
return dateString(new GregorianCalendar(GMTTimeZone).getTime());
|
||||
return dateString(new Date());
|
||||
}
|
||||
|
||||
public static String dateString(Date date) {
|
||||
return SimpleFormatter.format(date);
|
||||
synchronized (SimpleFormatter) {
|
||||
return SimpleFormatter.format(date);
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalize(String key) {
|
||||
|
@ -169,7 +173,9 @@ public class wikiBoard {
|
|||
System.out.println("DEBUG - ERROR: date field missing in wikiBoard");
|
||||
return new Date();
|
||||
}
|
||||
return SimpleFormatter.parse(c);
|
||||
synchronized (SimpleFormatter) {
|
||||
return SimpleFormatter.parse(c);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
return new Date();
|
||||
}
|
||||
|
@ -207,7 +213,9 @@ public class wikiBoard {
|
|||
try {
|
||||
String c = (String) record.get("date");
|
||||
if (c == null) return null;
|
||||
return SimpleFormatter.parse(c);
|
||||
synchronized (SimpleFormatter) {
|
||||
return SimpleFormatter.parse(c);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -389,7 +389,7 @@ public final class httpHeader extends TreeMap implements Map {
|
|||
if (containsKey(kind)) {
|
||||
Date parsedDate = serverDate.parseHTTPDate((String) get(kind));
|
||||
if (parsedDate == null) parsedDate = new Date();
|
||||
return new Date(parsedDate.getTime());
|
||||
return parsedDate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ public final class httpHeader extends TreeMap implements Map {
|
|||
if (containsKey(httpHeader.IF_RANGE)) {
|
||||
Date rangeDate = serverDate.parseHTTPDate((String) get(httpHeader.IF_RANGE));
|
||||
if (rangeDate != null)
|
||||
return new Date(rangeDate.getTime());
|
||||
return rangeDate;
|
||||
|
||||
return get(httpHeader.IF_RANGE);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,6 @@ import java.util.Arrays;
|
|||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
@ -109,7 +108,6 @@ public final class httpc {
|
|||
// final statics
|
||||
private static final String vDATE = "20040602";
|
||||
private static final int terminalMaxLength = 30000;
|
||||
private static final TimeZone GMTTimeZone = TimeZone.getTimeZone("GMT");
|
||||
private static final SimpleDateFormat HTTPGMTFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
|
||||
private static final HashMap reverseMappingCache = new HashMap();
|
||||
private static final HashSet activeConnections = new HashSet(); // all connections are stored here and deleted when they are finished
|
||||
|
@ -130,7 +128,7 @@ public final class httpc {
|
|||
|
||||
static {
|
||||
// set the time zone
|
||||
HTTPGMTFormatter.setTimeZone(GMTTimeZone); // The GMT standard date format used in the HTTP protocol
|
||||
HTTPGMTFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); // The GMT standard date format used in the HTTP protocol
|
||||
|
||||
// set time-out of InetAddress.getByName cache ttl
|
||||
java.security.Security.setProperty("networkaddress.cache.ttl" , "60");
|
||||
|
@ -343,7 +341,7 @@ public final class httpc {
|
|||
* @return Date-object with the current time.
|
||||
*/
|
||||
public static Date nowDate() {
|
||||
return new GregorianCalendar(GMTTimeZone).getTime();
|
||||
return new Date();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
|
|
|
@ -33,8 +33,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -818,10 +817,9 @@ public class kelondroCollectionIndex {
|
|||
|
||||
// finally dump the removed entries to a file
|
||||
newcommon.sort();
|
||||
TimeZone GMTTimeZone = TimeZone.getTimeZone("GMT");
|
||||
Calendar gregorian = new GregorianCalendar(GMTTimeZone);
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String filename = serverCodings.encodeHex(kelondroBase64Order.enhancedCoder.decode(new String(key))) + "_" + formatter.format(gregorian.getTime()) + ".collection";
|
||||
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
String filename = serverCodings.encodeHex(kelondroBase64Order.enhancedCoder.decode(new String(key))) + "_" + formatter.format(new Date()) + ".collection";
|
||||
File storagePath = new File(commonsPath, filename.substring(0, 2)); // make a subpath
|
||||
storagePath.mkdirs();
|
||||
File file = new File(storagePath, filename);
|
||||
|
|
|
@ -64,12 +64,10 @@ import java.net.InetAddress;
|
|||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TimeZone;
|
||||
import java.util.Vector;
|
||||
|
||||
import de.anomic.server.serverDomains;
|
||||
|
@ -85,9 +83,6 @@ public class ftpc {
|
|||
private PrintStream err;
|
||||
private boolean glob = true; // glob = false -> filenames are taken literally for mget, ..
|
||||
|
||||
// for time measurement
|
||||
private static final TimeZone GMTTimeZone = TimeZone.getTimeZone("PST"); // the GMT Time Zone
|
||||
|
||||
// transfer type
|
||||
private static final char transferType = 'i'; // transfer binary
|
||||
|
||||
|
@ -1673,7 +1668,7 @@ cd ..
|
|||
|
||||
private void get(String fileDest, String fileName) throws IOException {
|
||||
// store time for statistics
|
||||
long start = Calendar.getInstance(GMTTimeZone).getTime().getTime();
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
// prepare data channel
|
||||
if (DataSocketPassiveMode) createPassiveDataPort(); else createActiveDataPort();
|
||||
|
@ -1729,7 +1724,7 @@ cd ..
|
|||
//if (!success) throw new IOException(reply);
|
||||
|
||||
// write statistics
|
||||
long stop = Calendar.getInstance(GMTTimeZone).getTime().getTime();
|
||||
long stop = System.currentTimeMillis();
|
||||
out.print("---- downloaded " +
|
||||
((length < 2048) ? length + " bytes" : ((int) length / 1024) + " kbytes") +
|
||||
" in " +
|
||||
|
|
Loading…
Reference in New Issue
Block a user