Add scheduling
This commit is contained in:
parent
eaa2f7e296
commit
d4eeff7488
1 changed files with 15 additions and 20 deletions
|
@ -11,6 +11,8 @@ import java.io.IOException;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
@ -43,9 +45,9 @@ public class DHTNodeFinderThread implements Runnable{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startSender(){
|
private void startSender(){
|
||||||
new Thread(() -> {
|
Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(() -> {
|
||||||
while(true){
|
|
||||||
System.out.println("[BULK PING]");
|
System.out.println("[BULK PING]");
|
||||||
|
API.saveNodes();
|
||||||
for(InetSocketAddress socketAddress : DHT.getPeers().keySet()){
|
for(InetSocketAddress socketAddress : DHT.getPeers().keySet()){
|
||||||
String hostname = socketAddress.getHostName();
|
String hostname = socketAddress.getHostName();
|
||||||
int port = socketAddress.getPort();
|
int port = socketAddress.getPort();
|
||||||
|
@ -58,14 +60,7 @@ public class DHTNodeFinderThread implements Runnable{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
},0,15,TimeUnit.SECONDS);
|
||||||
Thread.sleep(15_000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
API.saveNodes();
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doPing(InetSocketAddress destination) throws IOException{
|
private void doPing(InetSocketAddress destination) throws IOException{
|
||||||
|
|
Loading…
Add table
Reference in a new issue