3
I developed a menu app for Android, the waiter by the app sees all the tables, the app opens the table, makes the order coming out in the kitchen and so on.
The web service returns a JSON for each request and makes the transactions in the database, the same is running in a Tomcat.
The application after a certain time of use can no longer connect to the server, after tests I saw that I receive a java.net.SocketTimeoutException
.
private static String sCookie;
public static String acessar(String url){
HttpURLConnection conn = null;
String conteudo = "";
try {
conn = (HttpURLConnection) ((new URL(url).openConnection()));
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
conn.setRequestProperty("Connection","Close");
if(sCookie != null && !"".equals(sCookie))
conn.setRequestProperty("Cookie", sCookie);
int responseCode = conn.getResponseCode();
if(responseCode == 200) {
conteudo = streamToStr(conn.getInputStream());
String cookie = conn.getHeaderField("set-cookie");
if(cookie != null && cookie.length() > 0)
sCookie = cookie;
}
return conteudo;
}
catch(Exception ex){
ex.printStackTrace();
} finally {
if(conn != null)
conn.disconnect();
}
return conteudo;
}
I thought it was the Tomcat, I changed the default settings on Connector
, but did not resolve.
<Connector port="9090"
enableLookups="false"
protocol = "HTTP/1.1"
acceptorThreadCount="2"
maxThreads="300"
connectionTimeout="30000"
compressableMimeTypes="text/*,application/x-javascript,application/javascript"
compressionMinSise="2048"
noCompressionUserAgents="gozilla, traviata"
maxSpareThreads="150"
maxRequestsPerChild="20000"
compression="force"
redirectPort="8443"
keepAlive="true"
keepAliveTimeOut="20000">
</Connector>
Thanks in advance for any help trying to figure out what might be causing this problem.
Why so little timeout time? 5000 is in milesseconds meaning the timeout is 5 seconds, the default for HTTP requests is 30000 (30 seconds)
– Hiago Souza
Before the timeout time was 15 seconds, when the waiter would consult the list of tables, the app opens the progressiDialog asking him to wait, and he would stay there for 15 seconds until giving the timeoutexception, so I decided to decrease why regardless of the time, has a certain moment that the app can no longer communicate with the server.
– Edson Silva
OK @Edson, but the default for Timeout is 30 seconds. Just to clarify. You considered calling your webservice using the REST Client to check if it takes?
– Hiago Souza
As this occurs after several requests, it would be good to check if your scripts are opening and closing the connection with the database. Check that processes started by Tomcat end at the end of the request.
– Hiago Souza
Hi @Hiagosouza, yes I got to test using Rest and got the same errors.
– Edson Silva
Another detail I forgot to mention, when I developed the app, I did the tests on my bike x there was at no time this type of error, the waiters use a Samsung Galaxy ace duos and with them happens what sitei in the post.
– Edson Silva
Ok, I’ve seen your android class now. It’s missing a Conn.Disconnect();
– Hiago Souza
this in Finally the Disconnect();
– Edson Silva