jquery-1.8.2.min.js:2 GET http://localhost:8080/api/trmnlInfoColctToFile.do?imei=A2&phoneSerial=testS…=lte&androidVersion=1.1&swVersion=aa_f10_1212&extra=extra1&_=1461227407494 net::ERR_CONNECTION_RESET
The error is the same as above.
I do an asynchronous communication 1000 times with ajax in the repetition sentence at the browser end. If you turn on the server and turn it on for the first 1,000 times, the request status of 5 times that have not been performed will be pending. From the second time, you can do all the requests 1000 times.
Currently, we are saving the data sent by the customer as a file, so we have to receive all 5 requests.
Where is this problem? Is it Tomcat's problem? Or is it ajax problem.
This is the browser code
<script type="text/javascript">
var i=0;
function testfunction(){
var testid = $("#Bid").val();
if(testid==""){
alert("Please enter your ID".");
return;
}
//http://localhost:8080/api/trmnlInfoColctToFile.do?imei=testIMEI3&phoneSerial=testSerial1&phoneModel=testModel1&phoneUptime=1:1:1&lineNumber=01000010001&pttNumber=1|123*456&networkName=lg&networkType=lte&androidVersion=1.1&swVersion=aa_f10_1212&extra=extra1
var i=0;
while(i!=1000){
var myurl = "http://localhost:8080/api/trmnlInfoColctToFile.do?imei="+testid+i+"&phoneSerial=testSerial1&phoneModel=testModel1&phoneUptime=1:1:1&lineNumber=01000010001&pttNumber=1|123*456&networkName=lg&networkType=lte&androidVersion=1.1&swVersion=aa_f10_1212&extra=extra1";
$.ajax({
type: 'GET',
url: myurl,
cache: false,
success: function(data) {
console.log ("Successful" + data);
},
error: function(xhr) {
console.log("Error: " + xhr.statusText);
}
});
i++;
}
console.log ("Exit");
}
</script>
It's a business code.
public synchronized void trmnlInfoColctToFile(){
try{
if(check==false){
wait();
check=true;
}
check = false;
System.out.println ("Do"+exc++);
String Time = new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar.getInstance().getTime());
StringBuffer sb = new StringBuffer();
sb.append(((TrmnlinfoColctVo)vo).getImei() == null ? "" : ((TrmnlinfoColctVo)vo).getImei());
sb.append(",").append(((TrmnlinfoColctVo)vo).getPhoneSerial() == null ? "" : ((TrmnlinfoColctVo)vo).getPhoneSerial());
sb.append(",").append(((TrmnlinfoColctVo)vo).getPhoneModel() == null ? "" : ((TrmnlinfoColctVo)vo).getPhoneModel());
sb.append(",").append(((TrmnlinfoColctVo)vo).getPhoneUptime() == null ? "" : ((TrmnlinfoColctVo)vo).getPhoneUptime());
sb.append(",").append(((TrmnlinfoColctVo)vo).getLineNumber() == null ? "" : ((TrmnlinfoColctVo)vo).getLineNumber());
sb.append(",").append(((TrmnlinfoColctVo)vo).getPttNumber() == null ? "" : ((TrmnlinfoColctVo)vo).getPttNumber());
sb.append(",").append(((TrmnlinfoColctVo)vo).getNetworkName() == null ? "" : ((TrmnlinfoColctVo)vo).getNetworkName());
sb.append(",").append(((TrmnlinfoColctVo)vo).getNetworkType() == null ? "" : ((TrmnlinfoColctVo)vo).getNetworkType());
sb.append(",").append(((TrmnlinfoColctVo)vo).getAndroidVersion() == null ? "" : ((TrmnlinfoColctVo)vo).getAndroidVersion());
sb.append(",").append(((TrmnlinfoColctVo)vo).getSwVersion() == null ? "" : ((TrmnlinfoColctVo)vo).getSwVersion());
sb.append(",").append(((TrmnlinfoColctVo)vo).getExtra() == null ? "" : ((TrmnlinfoColctVo)vo).getExtra());
String fileName = Time.substring(0, 10)+".req";
File AbsolPath = new File(fileName);
String Mypath = AbsolPath.getAbsolutePath();
Mypath = Mypath.substring(0,Mypath.lastIndexOf("\\"); // to the Eclipse folder
Mypath = Mypath.substring(0,Mypath.lastIndexOf("\\"); // to the tools folder
Mypath = Mypath.substring(0,Mypath.lastIndexOf("\\"); // to the project folder
Mypath = Mypath+"\\workspace\\KtpOta\\WebContent\\data\\ing";
//Communication test
File testPath = new File(Mypath+"\\"+((TrmnlinfoColctVo)vo).getImei());
FileWriter tfw = null;
tfw = new FileWriter(testPath, true);
tfw.write(sb.toString()+"\n");
tfw.close();
File myPath = new File(Mypath);
//create if directory does not exist
if(!myPath.exists()){
myPath.mkdirs();
}
File myFilePath = new File(Mypath+"\\"+fileName);
FileWriter fw = null;
if(myFilePath.isFile()){
fw = new FileWriter(myFilePath, true);
fw.write(sb.toString()+"\n");
fw.flush();
fw.close();
}else{
fw = new FileWriter(myFilePath, false);
fw.write(sb.toString()+"\n");
fw.flush();
fw.close();
}
if(check==false){
check = true;
notify();
}
}catch(Exception e){
System.out.println ("Processing Failed"+e);
}
}
Is it because I use the synchronization option on AJAX?
I came to an intuitive conclusion. The IO in the OS opens, writes, saves and closes files at a rate It was slower than Java's JVM speed, so I guessed that the file was not closed and opened again and was not processed again. As a countermeasure, files were created and backed up with Millisecond+user unique ID per request.
© 2024 OneMinuteCode. All rights reserved.