@Path("/getVersion")
@POST
@Produces(MediaType.APPLICATION_JSON)
public List getVersion(String getVersionJson) throws InterruptedException {
List outputList = new ArrayList();
try {
JSONArray jsonArr = new JSONArray(getVersionJson);
for (int j = 0; j < jsonArr.length(); j++) {
JSONObject jsonObj = jsonArr.getJSONObject(j);
String ip = jsonObj.getString("ipaddress");
String username = jsonObj.getString("username");
String password = jsonObj.getString("password");
new Thread() {
public void run() {
//outputList.add(ip);
final String connectionStatus = getSSHConnection(ip, username, password);
// outputList.add(connectionStatus);
if (connectionStatus.equals("Connected")) {
// outputList.add(connectionStatus);
//Version Check
expect.send("bwshowver" + "\n");
if (expect.expect("$") > -1) {
String contt = "";
contt = (expect.before);
if (contt != null && contt != "") {
contt = contt.replaceAll("\n+", "\n");
contt = contt.replaceAll(" +", " ");
String splitter[] = contt.split("\n");
for (int i = 0; i < splitter.length; i++) {
if (splitter[i].contains("Patches")) {
final String patches = splitter[i];
}
//version
if (splitter[i].contains("version")) {
// final String version = splitter[i];
outputList.add(splitter[i]);
}
}
} else {
final String v1 = "Error in version check";
System.out.println("Error in version check");
}
}
} else {
outputList.add(connectionStatus);
}
}
}.start();
}
} catch (Exception e) {
final String v = "Error";
// logger.error("Exception in getVersion Function-ServService Class: " + e.getMessage());
} finally {
stopSSH();
}
Thread.sleep(20000);
//outputList.add("ffk");
// outputList.add("f");
return outputList;
}
我已经创建了一个使用线程的方法,在这个方法中,我发送了一个包含JSON对象的JSON数组。之前我创建了这个方法时没有使用线程,它可以正常工作。但是现在在使用线程后,我会在不同的时间得到不同的结果。你能告诉我哪里出了问题吗?