मैंने कोड का एक टुकड़ा बनाया है जो एक आईपी पता (किसी अन्य वर्ग में मुख्य विधि से) लेता है और फिर प्रत्येक के रूप में प्रत्येक को पिंग करने वाले आईपी पतों की एक श्रृंखला के माध्यम से loops। मेरे पास इस पर एक जीयूआई फ्रंट एंड है और यह क्रैश हो रहा था (इसलिए मैंने मल्टीथ्रेडिंग क्यों की है। मेरी समस्या यह है कि अब मैं अपने पिंग कोड में एक तर्क के रूप में आईपी पता नहीं ले सकता क्योंकि यह कॉल करने योग्य है। मैंने पूरी खोज की है इसके लिए और इसे पाने के लिए कोई रास्ता नहीं मिल रहा है। क्या तर्क देने के लिए कॉल करने योग्य विधि का कोई तरीका है? यदि नहीं है तो क्या मैं ऐसा करने का कोई अन्य तरीका नहीं कर रहा हूं?क्या कॉल करने योग्य विधि में कोई तर्क लेने का कोई तरीका है?
मेरा नमूना कोड:।
public class doPing implements Callable<String>{
public String call() throws Exception{
String pingOutput = null;
//gets IP address and places into new IP object
InetAddress IPAddress = InetAddress.getByName(IPtoPing);
//finds if IP is reachable or not. a timeout timer of 3000 milliseconds is set.
//Results can vary depending on permissions so cmd method of doing this has also been added as backup
boolean reachable = IPAddress.isReachable(1400);
if (reachable){
pingOutput = IPtoPing + " is reachable.\n";
}else{
//runs ping command once on the IP address in CMD
Process ping = Runtime.getRuntime().exec("ping " + IPtoPing + " -n 1 -w 300");
//reads input from command line
BufferedReader in = new BufferedReader(new InputStreamReader(ping.getInputStream()));
String line;
int lineCount = 0;
while ((line = in.readLine()) != null) {
//increase line count to find part of command prompt output that we want
lineCount++;
//when line count is 3 print result
if (lineCount == 3){
pingOutput = "Ping to " + IPtoPing + ": " + line + "\n";
}
}
}
return pingOutput;
}
}
IPtoPing तर्क यह है कि लिया गया था हुआ करता था
तो .... यह यदि आप किसी अन्य समारोह जो प्रतिदेय पुनरावृति करने की कोशिश करता करने के लिए एक पैरामीटर के रूप प्रतिदेय पारित काम नहीं करेगा तर्कों की एक सरणी के खिलाफ यह पारित किया गया था ... – Michael
क्या यह एक बयान या प्रश्न के रूप में है? किसी भी तरह से, मैं यह नहीं समझ सकता कि आप क्या कह रहे हैं/पूछ रहे हैं। –