This commit is contained in:
Redkale
2018-05-19 10:19:41 +08:00
parent 6acb17da7c
commit 6e81541a3b
5 changed files with 42 additions and 21 deletions

View File

@@ -124,7 +124,11 @@ public class TransportFactory {
return t; return t;
}); });
this.scheduler.scheduleAtFixedRate(() -> { this.scheduler.scheduleAtFixedRate(() -> {
try {
checks(); checks();
} catch (Throwable t) {
logger.log(Level.SEVERE, "TransportFactory schedule(interval=" + checkinterval + "s) check error", t);
}
}, checkinterval, checkinterval, TimeUnit.SECONDS); }, checkinterval, checkinterval, TimeUnit.SECONDS);
if (this.pinginterval > 0) { if (this.pinginterval > 0) {

View File

@@ -407,8 +407,13 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
final DateFormat gmtDateFormat = new SimpleDateFormat("EEE, d MMM y HH:mm:ss z", Locale.ENGLISH); final DateFormat gmtDateFormat = new SimpleDateFormat("EEE, d MMM y HH:mm:ss z", Locale.ENGLISH);
gmtDateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); gmtDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
currDateBytes = ("Date: " + gmtDateFormat.format(new Date()) + "\r\n").getBytes(); currDateBytes = ("Date: " + gmtDateFormat.format(new Date()) + "\r\n").getBytes();
final int dp = datePeriod;
this.dateScheduler.scheduleAtFixedRate(() -> { this.dateScheduler.scheduleAtFixedRate(() -> {
try {
currDateBytes = ("Date: " + gmtDateFormat.format(new Date()) + "\r\n").getBytes(); currDateBytes = ("Date: " + gmtDateFormat.format(new Date()) + "\r\n").getBytes();
} catch (Throwable t) {
logger.log(Level.SEVERE, "HttpServer schedule(interval=" + dp + "ms) date-format error", t);
}
}, 1000 - System.currentTimeMillis() % 1000, datePeriod, TimeUnit.MILLISECONDS); }, 1000 - System.currentTimeMillis() % 1000, datePeriod, TimeUnit.MILLISECONDS);
dateSupplier = () -> currDateBytes; dateSupplier = () -> currDateBytes;
} }

View File

@@ -107,8 +107,12 @@ public class WebSocketEngine {
long delay = (liveinterval - System.currentTimeMillis() / 1000 % liveinterval) + index * 5; long delay = (liveinterval - System.currentTimeMillis() / 1000 % liveinterval) + index * 5;
final int intervalms = liveinterval * 1000; final int intervalms = liveinterval * 1000;
scheduler.scheduleWithFixedDelay(() -> { scheduler.scheduleWithFixedDelay(() -> {
try {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
getLocalWebSockets().stream().filter(x -> (now - x.getLastReadTime()) > intervalms).forEach(x -> x.sendPing()); getLocalWebSockets().stream().filter(x -> (now - x.getLastReadTime()) > intervalms).forEach(x -> x.sendPing());
} catch (Throwable t) {
logger.log(Level.SEVERE, "WebSocketEngine schedule(interval=" + liveinterval + "s) ping error", t);
}
}, delay, liveinterval, TimeUnit.SECONDS); }, delay, liveinterval, TimeUnit.SECONDS);
if (logger.isLoggable(Level.FINEST)) logger.finest(this.getClass().getSimpleName() + "(" + engineid + ")" + " start keeplive(wsmaxconns:" + wsmaxconns + ", delay:" + delay + "s, interval:" + liveinterval + "s) scheduler executor"); if (logger.isLoggable(Level.FINEST)) logger.finest(this.getClass().getSimpleName() + "(" + engineid + ")" + " start keeplive(wsmaxconns:" + wsmaxconns + ", delay:" + delay + "s, interval:" + liveinterval + "s) scheduler executor");
} }

View File

@@ -123,6 +123,7 @@ public class CacheMemorySource<V extends Object> extends AbstractService impleme
}); });
final List<String> keys = new ArrayList<>(); final List<String> keys = new ArrayList<>();
scheduler.scheduleWithFixedDelay(() -> { scheduler.scheduleWithFixedDelay(() -> {
try {
keys.clear(); keys.clear();
int now = (int) (System.currentTimeMillis() / 1000); int now = (int) (System.currentTimeMillis() / 1000);
container.forEach((k, x) -> { container.forEach((k, x) -> {
@@ -134,6 +135,9 @@ public class CacheMemorySource<V extends Object> extends AbstractService impleme
CacheEntry entry = container.remove(key); CacheEntry entry = container.remove(key);
if (expireHandler != null && entry != null) expireHandler.accept(entry); if (expireHandler != null && entry != null) expireHandler.accept(entry);
} }
} catch (Throwable t) {
logger.log(Level.SEVERE, "CacheMemorySource schedule(interval=" + 10 + "s) error", t);
}
}, 10, 10, TimeUnit.SECONDS); }, 10, 10, TimeUnit.SECONDS);
if (logger.isLoggable(Level.FINEST)) logger.finest(self.getClass().getSimpleName() + ":" + self.resourceName() + " start schedule expire executor"); if (logger.isLoggable(Level.FINEST)) logger.finest(self.getClass().getSimpleName() + ":" + self.resourceName() + " start schedule expire executor");
} }

View File

@@ -118,6 +118,7 @@ public final class EntityCache<T> {
return t; return t;
}); });
this.scheduler.scheduleAtFixedRate(() -> { this.scheduler.scheduleAtFixedRate(() -> {
try {
ConcurrentHashMap newmap2 = new ConcurrentHashMap(); ConcurrentHashMap newmap2 = new ConcurrentHashMap();
List<T> all2 = info.fullloader.apply(info.source, type); List<T> all2 = info.fullloader.apply(info.source, type);
if (all2 != null) { if (all2 != null) {
@@ -127,6 +128,9 @@ public final class EntityCache<T> {
} }
this.list = all2 == null ? new ConcurrentLinkedQueue() : new ConcurrentLinkedQueue(all2); this.list = all2 == null ? new ConcurrentLinkedQueue() : new ConcurrentLinkedQueue(all2);
this.map = newmap2; this.map = newmap2;
} catch (Throwable t) {
logger.log(Level.SEVERE, type + " schedule(interval=" + interval + "s) Cacheable error", t);
}
}, interval - System.currentTimeMillis() / 1000 % interval, interval, TimeUnit.SECONDS); }, interval - System.currentTimeMillis() / 1000 % interval, interval, TimeUnit.SECONDS);
} }
} }