以下是我的主要课程。
public class ShareData {
/**
* @param args
*/
public static void main(String[] args) {
ShareReader aShareReader = new ShareReader("http://test.com:9000", "dilip.id@gmail.com", "password");
Thread fileThread = new Thread(aShareReader);
fileThread.run(); // fileThread.start() not calling the run() method
}
}
如果我键入 fileThread.run() 调用运行方法。如果我调用 fileThread.start() 则不会调用运行方法。以下是我的线程类。我不知道我做错了什么。
public class ShareReader implements Runnable {
private String itsShareURL = null;
private String itsUserId = null;
private String itsPassword = null;
private String itsAuthToken = null;
private String itsLoginURL = null;
private String itsChannelUpateURL = null;
/**
*
*/
public ShareReader(String theShareURL, String theUserId, String thePassword) {
this.itsShareURL = theShareURL;
this.itsUserId = theUserId;
this.itsPassword = thePassword;
this.itsLoginURL = itsShareURL + "/v1.0-SNAPSHOT/login";
this.itsChannelUpateURL = itsShareURL + "/v1.0-SNAPSHOT/updateChannelSubscription/";
}
public void run() {
JSONObject json;
JSONArray jsonArray;
itsAuthToken = getToken(itsUserId, itsPassword);
updateChannelList(itsAuthToken);
String aURL = "http://test.com:9000/v1.0-SNAPSHOT/userTimeline/"+itsAuthToken+"/";
try {
String lat = null;
String lon = null;
String udid = null;
String dateTime = null;
String eventID = null;
aEventBean = new EventBean();
jsonArray = readJsonArrayFromUrl(aURL);
for (int i = 0; i < jsonArray.length(); i++) {
json = jsonArray.getJSONObject(i);
lat = json.getString("lat");
lon = json.getString("lon");
udid = json.getString("udid");
eventID = json.getString("eventId");
dateTime = json.getString("dateTime");
aEventBean.setItsLatitude(lat);
aEventBean.setItsLongitude(lon);
aEventBean.setItsUDID(udid);
aEventBean.setItsEventIdentifier(eventID);
aEventBean.setItsDateTime(dateTime);
System.out.println(udid + " ---> " +lat + " ==== " + lon);
sendData(aEventBean);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
对不起,如果我问这么基本的问题.. 理想情况下,我需要做 fileThread.start() 来启动一个线程.. 在此先感谢...