package com.aig.ecompassios.ecard;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import net.sf.json.JSONObject;
public class EcardThread extends Thread {
static int i=0;
static String ebToken="";
static long time;
public EcardThread(int i,String ebToken){
this.i = i;
this.ebToken = ebToken;
}
public static String login(){
// String login ="http://10.72.3.53:7042/eCOMPASS/AppleWebService?_command_=AppleWebService&module=LoginSecurityModule&actionType=UserLogin&locale=en_HK&userId=ecarduser&password=b123456b&deviceId=A5B08C51-2092-5F39-A2C2-D79AE01A27AE&deviceType=iPhone%20Simulator&deviceToken=ajsdiofjaosidjf09a9h2093f";
String login = "http://localhost:9080/eCOMPASS/AppleWebService?_command_=AppleWebService&module=LoginSecurityModule&actionType=UserLogin&locale=en_HK&userId=member_lily002&password=a123456a&deviceId=A5B08C51-2092-5F39-A2C2-D79AE01A27AE&deviceType=iPhone%20Simulator&deviceToken=ajsdiofjaosidjf09a9h2093f";
URL loginUrl;
StringBuilder jsonLogin = new StringBuilder();
//login url
try {
loginUrl = new URL(login);
HttpURLConnection urlcon = (HttpURLConnection)loginUrl.openConnection();
urlcon.connect(); //获取连接
InputStream is = urlcon.getInputStream();
BufferedReader buffer = new BufferedReader(new InputStreamReader(is,"UTF-8"));
String l = null;
while((l=buffer.readLine())!=null){
jsonLogin.append(l);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(jsonLogin.toString());
JSONObject jsonObject = JSONObject.fromObject(jsonLogin.toString());
ebToken = jsonObject.getString("ebToken");
return ebToken;
}
public void run() {
String ecard="http://localhost:9080/eCOMPASS/AppleWebService?_command_=AppleWebService&module=ECardModule&actionType=eCardImageInformation&locale=en_HK&ebToken=";
//String ecard = "http://10.72.3.53:7042/eCOMPASS/AppleWebService?_command_=AppleWebService&module=ECardModule&actionType=eCardImageInformation&locale=en_HK&ebToken=";
long begintime = System.currentTimeMillis();
StringBuilder jsonECard = new StringBuilder();
try {
//ECard url
Thread.sleep(1000);
URL eCardURL = new URL(ecard+ebToken);
HttpURLConnection urlconECard = (HttpURLConnection)eCardURL.openConnection();
urlconECard.connect(); //获取连接
InputStream isECard = urlconECard.getInputStream();
BufferedReader bufferECard = new BufferedReader(new InputStreamReader(isECard,"UTF-8"));
String lECard = null;
while((lECard=bufferECard.readLine())!=null){
jsonECard.append(lECard);
}
System.out.println(jsonECard.toString());
System.out.println("Thread"+i+"执行时间为:"+(System.currentTimeMillis()-begintime)+"毫秒");
time+=(System.currentTimeMillis()-begintime);
System.out.println(time+"++++++");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
long begintime = System.currentTimeMillis();
String ebToken = login();
/*for (int i = 0; i < 2; i++) {
EcardThread th = new EcardThread(i,ebToken);
th.start();
}*/
System.out.println(time+"=======");
while(time<0.3*60*1000){
EcardThread th = new EcardThread(i,ebToken);
th.start();
i=i+1;
}
System.out.println("总执行时间为:"+(System.currentTimeMillis()-begintime)+"毫秒");
}
}