Kkk.
Kkk.

Reputation: 1

Java android ava.util.concurrent.ThreadPoolExecutor

In this line :

 while ((bytesRead = inputStream.read(content)) != -1) {

This line is inside in astyntask

in logs I see this :

 at java.net.PlainSocketImpl.read(PlainSocketImpl.java:492)
 W/System.err:     at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
 W/System.err:     at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:241)
 W/System.err:     at java.io.InputStream.read(InputStream.java:162)
 W/System.err:     at pl.eltegps.teminalmobile.Activity.MainActivity$connectTask3.doInBackground(MainActivity.java:1353)
 W/System.err:     at pl.eltegps.teminalmobile.Activity.MainActivity$connectTask3.doInBackground(MainActivity.java:1205)
 W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
 W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
 W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
 W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
 W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
 W/System.err:     at java.lang.Thread.run(Thread.java:841)

Upvotes: 0

Views: 1739

Answers (1)

pleft
pleft

Reputation: 7905

AsyncTask documentation has some threading rules:

Threading rules

There are a few threading rules that must be followed for this class to work properly:

  • The AsyncTask class must be loaded on the UI thread. This is done automatically as of JELLY_BEAN.
  • The task instance must be created on the UI thread.
  • execute(Params...) must be invoked on the UI thread.
  • Do not call onPreExecute(), onPostExecute(Result), doInBackground(Params...), onProgressUpdate(Progress...) manually.
  • The task can be executed only once (an exception will be thrown if a second execution is attempted.)

You cannot execute multiple times the same task, only once.

UPDATE

In your "paste.ofcode.org" url it seems that you break 3 rules of the threading rules above (boldly marked)

Rules 2&3 break here, (why start a new thread to execute an AsyncTask?):

thread = new Thread() {
            @Override
            public void run() {
                new connectTask3().execute();
            }
        };
        thread.start();

Do not create a new thread, instead delete the above code and replace it with just:

new connectTask3().execute();

Upvotes: 1

Related Questions