SocketTimeoutException Android SocketTimeoutException Android multithreading multithreading

SocketTimeoutException Android


it is a while I worked with this, but one article is really recommended to read when looking for performance: http://www.kegel.com/java/wp-javaio.html

The connection timeout could be caused on the server side, assuming you are connected to a web server, check what errors you receive there.

The GC statements are not surprising. This is not a memory leak, but Java cleaning up. From above article:

First, if we look at the first line of the while loop, we see that a new String object is being created for every line of the file being read:

while ((line = in.readLine()) != null) {

This means, for example, that for a 100,000 line file 100,000 String objects would be created. Creating a large number of objects incurs costs in three ways: Time and memory to allocate the space for the objects, time to initialize the objects, time to garbage collect the objects.

Regarding multiple threading, you should provide a bit more code. Your method is synchronized, so you at least avoid multiple invocations on the same instance at the same time. The NW code is, at quick glance, safe.

My debug strategy would be to look at the server side first and second store timestamps on when you receive a line of input to see if there are gaps occurring (transmission errors).

Good luck