I have a code which has following methods:
downloadFile() - download file from ftpserver
processFile() - read file line by line and process the line
sendSMS() - send SMS to vendors how many records got processed.
The processFile
method reads each line,builds a URL string and hits URL.To make the process faster I have used thread concept.
//snippet in processFile method
while ((sCurrentLine = br.readLine()) != null) {
String[] arr = sCurrentLine.split("\t");
if (//some condition) {
String url = //build url from the current line
Thread t = new Thread(new MyClass(url));
t.start();
}
}
public MyClass(String strUrl) {
this.strUrl = strUrl;
}
public void run() {
urlHit(strUrl);//call function to hit current URL
}
Now my concern is sendSMS
method should get called only after all URLs got hit.
I tried using join
method which works fine but it is as good as not using threads.