mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-27 00:45:23 -04:00
P2P network improvements
This commit is contained in:
parent
900f89ce37
commit
f0d727e345
23 changed files with 218 additions and 257 deletions
|
@ -1,69 +0,0 @@
|
|||
package io.bitsquare.common;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Random;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class DefaultJavaTimer implements Timer {
|
||||
private final Logger log = LoggerFactory.getLogger(DefaultJavaTimer.class);
|
||||
private java.util.Timer timer;
|
||||
|
||||
public DefaultJavaTimer() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timer runLater(Duration delay, Runnable runnable) {
|
||||
if (timer == null) {
|
||||
timer = new java.util.Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("TimerTask-" + new Random().nextInt(10000));
|
||||
try {
|
||||
UserThread.execute(runnable::run);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("Executing timerTask failed. " + t.getMessage());
|
||||
}
|
||||
}
|
||||
}, delay.toMillis());
|
||||
} else {
|
||||
log.warn("runLater called on an already running timer.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timer runPeriodically(java.time.Duration interval, Runnable runnable) {
|
||||
if (timer == null) {
|
||||
timer = new java.util.Timer();
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("TimerTask-" + new Random().nextInt(10000));
|
||||
try {
|
||||
UserThread.execute(runnable::run);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
log.error("Executing timerTask failed. " + t.getMessage());
|
||||
}
|
||||
}
|
||||
}, interval.toMillis(), interval.toMillis());
|
||||
} else {
|
||||
log.warn("runLater called on an already running timer.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,8 @@ package io.bitsquare.common;
|
|||
import java.time.Duration;
|
||||
|
||||
public interface Timer {
|
||||
boolean STRESS_TEST = false;
|
||||
|
||||
Timer runLater(java.time.Duration delay, Runnable action);
|
||||
|
||||
Timer runPeriodically(Duration interval, Runnable runnable);
|
||||
|
|
|
@ -46,7 +46,7 @@ public class UserThread {
|
|||
static {
|
||||
// If not defined we use same thread as caller thread
|
||||
executor = MoreExecutors.directExecutor();
|
||||
timerClass = DefaultJavaTimer.class;
|
||||
timerClass = FrameRateTimer.class;
|
||||
}
|
||||
|
||||
private static Executor executor;
|
||||
|
|
|
@ -60,8 +60,8 @@ public class Utilities {
|
|||
public static ListeningExecutorService getListeningExecutorService(String name,
|
||||
int corePoolSize,
|
||||
int maximumPoolSize,
|
||||
long keepAliveTime) {
|
||||
return MoreExecutors.listeningDecorator(getThreadPoolExecutor(name, corePoolSize, maximumPoolSize, keepAliveTime));
|
||||
long keepAliveTimeInSec) {
|
||||
return MoreExecutors.listeningDecorator(getThreadPoolExecutor(name, corePoolSize, maximumPoolSize, keepAliveTimeInSec));
|
||||
}
|
||||
|
||||
public static ThreadPoolExecutor getThreadPoolExecutor(String name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue