我有一些代码在这里
public void doScan() {
Log.i(LOG_TAG, "Start scanning");
ExecutorService executor = Executors.newFixedThreadPool(NB_THREADS);
for(int dest=0; dest<255; dest++) {
String host = "192.168.5." + dest; //add net address instead of hardcoding
executor.execute(pingRunnable(host));
}
Log.i(LOG_TAG, "Waiting for executor to terminate...");
executor.shutdown();
try { executor.awaitTermination(10*1000, TimeUnit.MILLISECONDS); } catch (InterruptedException ignored) { }
Log.i(LOG_TAG, "Scan finished");
}
private Runnable pingRunnable(final String host) {
return new Runnable() {
public void run() {
Log.v(LOG_TAG, "Pinging " + host + "...");
try {
Socket s = null;
s = new Socket(InetAddress.getByName(host), ACES_PORT);
Log.v(LOG_TAG, "conn:"+s.toString());
if(s.isConnected()){
Log.v(LOG_TAG, "connected " + host);
foundDevicesArray.add(host);
}
} catch (UnknownHostException e) {
Log.e(LOG_TAG, "Not found", e);
} catch (IOException e) {
Log.e(LOG_TAG, "IO Error", e);
}
}
};
}
如果主机在线程内连接,我正在尝试保存它。
我有一个全局的(我是 android 的新手,所以我不确定它是否是这样的)ArrayList,在我执行 ArrayList.add(host) 的线程内它崩溃了我不知道如何获取来自崩溃的常见错误消息。