简体   繁体   中英

I get “Background sticky concurrent mark sweep G” in logs and then nothing happens

I am trying to connect to a FTP server and displaying data on my android app after pulling it from the server, but I have not been able to figure it out. I am facing the above mentioned problem. FTPDownloader class is inside the MainActivity Class and I call it by new FTPDownloader().execute(); . I call the doInBackground() of FTPDownloader() after pressing a button in MainActivity class. But nothing happens as if the doInBackground() method never ran. The app does not freeze though but nothing happens either. Thanks in advance, any help appreciated.

   private class FTPDownloader extends AsyncTask<Void, Void, Void> {

        FTPClient ftp = null;
        InputStream in;

        public FTPDownloader() {
            ftp = null;
        }


        public void disconnect() {
            if (this.ftp.isConnected()) {
                try {
                    this.ftp.logout();
                    this.ftp.disconnect();
                } catch (IOException f) {
                    // do nothing as file is already downloaded from FTP server
                }
            }
        }

        @Override
        protected Void doInBackground(Void... voids) {
            try {

                ftp = new FTPClient();
                ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
                int reply;
                ftp.connect("12.123.12.123");
                reply = ftp.getReplyCode();
                if (!FTPReply.isPositiveCompletion(reply)) {
                    ftp.disconnect();
                    throw new Exception("Exception in connecting to FTP Server");
                }
                ftp.login("user1234","1234" );
                ftp.setFileType(FTP.BINARY_FILE_TYPE);
                ftp.enterLocalPassiveMode();
                in = ftp.retrieveFileStream("filePath");


            } catch (Exception e) {
                e.printStackTrace();
                Log.i("FTP", "Error Occurred.");

            }
             try {

                int data = in.read();

                while (data != -1) {
                    String s = "";
                    char ch = (char) data;
                    if (ch != ',') {
                        s = s + ch;
                    } else {
                        s = s + " ";
                        gblprpd.add(s);
                        data = in.read();
                    }
                }
                in.close();

                for (int i = 0; i < gblprpd.size(); ++i) {
                    String s = "";
                    for (int j = 0; j < 9; ++j) {
                        ++i;
                        s = s + gblprpd.get(i);
                    }

                    dta.add(s);
                }
            } catch (IOException e) {
                e.printStackTrace();
                Log.i("FTP", "Error Occurred");

            }

            disconnect();
            return null;
        }

        @Override
        protected void onPreExecute()
        {

        }

        @Override
        protected void onPostExecute(Void cd) {


                    TextView output = (TextView) findViewById(R.id.output);
                    output.setText("Data Retrieved:");
                    for (int k = 0; k < dta.size(); ++k) {
                        roes.get(k + 1).setText(dta.get(k));
                    }
                    for (int k = dta.size() + 1; k < 16; ++k)
                        roes.get(k).setVisibility(View.GONE);
                    ScrollView sv = (ScrollView) findViewById(R.id.sv);
                    sv.setVisibility(View.VISIBLE);
                    HorizontalScrollView hsv = (HorizontalScrollView) findViewById(R.id.hsv);
                    hsv.setVisibility(View.VISIBLE);


    }
}


}

The logs are:

06-12 21:08:30.797 23404-23469/com.example.quickstart I/System.out: 220 Microsoft FTP Service
06-12 21:08:30.800 23404-23469/com.example.quickstart I/System.out: USER user1234
06-12 21:08:30.861 23404-23469/com.example.quickstart I/System.out: 331 Password required
06-12 21:08:30.862 23404-23469/com.example.quickstart I/System.out: PASS 1234
06-12 21:08:30.936 23404-23469/com.example.quickstart I/System.out: 230 User logged in.
06-12 21:08:30.938 23404-23469/com.example.quickstart I/System.out: TYPE I
06-12 21:08:31.018 23404-23469/com.example.quickstart I/System.out: 200 Type set to I.
06-12 21:08:31.019 23404-23469/com.example.quickstart I/System.out: PASV
06-12 21:08:31.082 23404-23469/com.example.quickstart I/System.out: 227 Entering Passive Mode (14,141,70,165,66,149).
06-12 21:08:31.145 23404-23469/com.example.quickstart I/System.out: RETR File\Path
06-12 21:08:31.213 23404-23469/com.example.quickstart I/System.out: 125 Data connection already open; Transfer starting.
06-12 21:08:46.814 23404-23415/com.example.quickstart I/art: Background sticky concurrent mark sweep GC freed 910864(25MB) AllocSpace objects, 0(0B) LOS objects, 27% free, 29MB/40MB, paused 1.234ms total 106.681ms
06-12 21:08:46.976 23404-23415/com.example.quickstart I/art: Background sticky concurrent mark sweep GC freed 926388(25MB) AllocSpace objects, 0(0B) LOS objects, 28% free, 29MB/40MB, paused 1.118ms total 104.876ms

Please help, any help appreciated. Thanks in advance

You are reading bytes off of an FTP connection in onPostExecute() . onPostExecute() is run on the main application thread. Hence, you are doing network I/O on the main application thread.

Move all of your code that uses the FTP connection into doInBackground() . Use the downloaded data in onPostExecute() .

Also note that you do not need runOnUiThread() in onPostExecute() , as onPostExecute() runs on the main application ("UI") thread already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM