PHP 발리 라이브러리를 사용하여 서버에서 큰 json 데이터를 가져 오는 데 너무 많은 시간이 걸립니다.

Jay Raotole

발리 라이브러리를 사용하여 PHP 서버의 데이터를 동기화하는 앱을 개발 중 json입니다. PHP에서 배열 응답을 받고 있습니다. 응답이 적 으면 완벽하게 작동합니다. 그러나 문제 json는 매우 클 때 발생합니다 . 동기화를 위해 xaamp를 사용하고 있습니다. 데이터를로드하는 데 너무 많은 시간이 걸립니다. 때로는 데이터를 전혀 얻지 못합니다. 나는 jsonPHP 배열 에서 진술을 준비하고 간단한 배열 목록에 추가하고 있습니다.

다음과 같이 logcat 오류가 발생합니다.

36.713ms
W/art: Suspending all threads took: 7.657ms
I/art: Waiting for a blocking GC Alloc
W/art: Suspending all threads took: 85.126ms
W/art: Suspending all threads took: 40.203ms
I/art: Background partial concurrent mark sweep GC freed 541(18KB) AllocSpace objects, 33(130MB) LOS objects, 11% free, 123MB/139MB, paused 42.528ms total 557.827ms
I/art: WaitForGcToComplete blocked for 328.549ms for cause Alloc
I/art: Starting a blocking GC Alloc
W/art: Suspending all threads took: 5.369ms
I/art: Background sticky concurrent mark sweep GC freed 105(3KB) AllocSpace objects, 3(11MB) LOS objects, 0% free, 142MB/142MB, paused 7.807ms total 52.573ms
W/art: Suspending all threads took: 5.261ms
W/art: Suspending all threads took: 294.041ms
W/art: Suspending all threads took: 38.308ms
I/art: Background partial concurrent mark sweep GC freed 388(13KB) AllocSpace objects, 26(103MB) LOS objects, 10% free, 133MB/149MB, paused 40.009ms total 515.759ms
W/art: Suspending all threads took: 5.063ms
I/art: Background sticky concurrent mark sweep GC freed 157(5KB) AllocSpace objects, 3(11MB) LOS objects, 0% free, 150MB/150MB, paused 7.052ms total 34.742ms
I/art: Waiting for a blocking GC Alloc
W/art: Suspending all threads took: 129.556ms
I/art: Background partial concurrent mark sweep GC freed 494(16KB) AllocSpace objects, 36(142MB) LOS objects, 12% free, 110MB/126MB, paused 1.517ms total 672.880ms
I/art: WaitForGcToComplete blocked for 485.833ms for cause Alloc
I/art: Starting a blocking GC Alloc
W/art: Suspending all threads took: 13.120ms
I/art: Background sticky concurrent mark sweep GC freed 104(3KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 138MB/138MB, paused 16.321ms total 38.525ms
W/art: Suspending all threads took: 9.983ms
W/art: Suspending all threads took: 285.230ms
W/art: Suspending all threads took: 38.702ms
I/art: Background partial concurrent mark sweep GC freed 435(14KB) AllocSpace objects, 27(106MB) LOS objects, 11% free, 127MB/143MB, paused 40.305ms total 493.740ms
W/art: Suspending all threads took: 5.107ms
I/art: Background sticky concurrent mark sweep GC freed 156(5KB) AllocSpace objects, 3(11MB) LOS objects, 0% free, 145MB/145MB, paused 6.856ms total 25.414ms
W/art: Suspending all threads took: 413.504ms
W/art: Suspending all threads took: 56.440ms
I/art: Background partial concurrent mark sweep GC freed 14(464B) AllocSpace objects, 9(35MB) LOS objects, 12% free, 115MB/131MB, paused 59.022ms total 496.519ms
I/art: Background sticky concurrent mark sweep GC freed 154(5KB) AllocSpace objects, 3(11MB) LOS objects, 0% free, 133MB/133MB, paused 5.741ms total 23.296ms
I/art: Waiting for a blocking GC Alloc
W/art: Suspending all threads took: 96.541ms
W/art: Suspending all threads took: 43.589ms
I/art: Background partial concurrent mark sweep GC freed 548(18KB) AllocSpace objects, 33(130MB) LOS objects, 11% free, 122MB/138MB, paused 45.755ms total 511.247ms
I/art: WaitForGcToComplete blocked for 332.277ms for cause Alloc
I/art: Starting a blocking GC Alloc
W/art: Suspending all threads took: 12.093ms
I/art: Background sticky concurrent mark sweep GC freed 104(3KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 150MB/150MB, paused 15.972ms total 51.520ms
W/art: Suspending all threads took: 7.796ms

내 json 배열은 다음 링크와 같습니다. http://www.ktronsystem.com/data.json

내 안드로이드 코드는

        public void m461async(){
        if (!(co.loggedInUserUniqid == "")) {
            jdialog= new ProgressDialog(all.this);
            jdialog.setMessage("m462   Please wait..We are processing your request.");
            jdialog.setIndeterminate(false);
            jdialog.setCancelable(false);
            jdialog.show();

            final Cursor mall = co.data_db.rawQuery("select * from mall", null);
            mall.moveToFirst();
            final int mrows = mall.getCount();
            System.out.print(mrows+"    ababababababababqa" );

            for (int idx = 0; idx < mrows; idx++) {
                System.out.print("loop of m462 55555555555555555555555");
                mall.moveToPosition(idx);
                mtempidx = idx;
                final String mfilename = f1.getCol(mall, "filename").toLowerCase().trim();
                String mfilepath = co.getDataPath(cn) + "/";
                final String mfilefullname = mfilepath + mfilename;

                if (new File(mfilefullname).exists()) {
                    StringRequest stringRequest= new StringRequest(Request.Method.POST, murl + "getonlinem461data.php",
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(final String response) {
                                    mjay = mjay + 1;
                                    System.out.println(mjay+ "  m461111111111111111"+response);

                                    class m461prepare extends AsyncTask<String, String, Integer> {
                                        @Override
                                        protected Integer doInBackground(String... params) {
                                            msuccess=1;
                                            System.out.println(mjay+"  m46211111111111111"+response);
                                            final String mquery="insert into m462 (accode,book,date,vno1,vno2,vno3,part,tot_debit,tot_credit,balance,cl_type,m462index) values ";
                                            String mquery2="";

                                            try {
                                                System.out.print("zzzzzzzzzzzzzzzzzzzzzzzzzzz");

                                                final SQLiteDatabase mdb1 =SQLiteDatabase.openDatabase(co.getDataPath(cn)+"/"+mfilename, null, SQLiteDatabase.OPEN_READWRITE);
                                                mdb1.execSQL("delete from m462");
                                                mdb1.close();
                                                JSONArray arr = new JSONArray(response);
                                                final ContentValues insertValues = new ContentValues();
                                                System.out.print("xxxxxxxxxxxxxxxxxxxxxx");

                                                if (arr.isNull(0)==false) {
                                                    System.out.print("ccccccccccccccccccccccccc");

                                                    for (int i = 0; i < arr.length(); i++) {
                                                        final JSONObject obj = (JSONObject) arr.get(i);
                                                        final String maccode = obj.get("maccode").toString();
                                                        final String mbook = obj.get("mbook").toString();
                                                        final String mdate = obj.get("mdate").toString();
                                                        final String mvno1 = obj.get("mvno1").toString();
                                                        final String mvno2 = obj.get("mvno2").toString();
                                                        final String mvno3 = obj.get("mvno3").toString();
                                                        final String mpart = obj.get("mpart").toString();
                                                        final String mtot_debit = obj.get("mtot_debit").toString();
                                                        final String mtot_credit = obj.get("mtot_credit").toString();
                                                        final String mbalance = obj.get("mbalance").toString();
                                                        final String mcl_type = obj.get("mcl_type").toString();
                                                        final String mm462index = obj.get("mm462index").toString();

                                                        mquery2 = mquery2
                                                                + "('" + f1.abc(maccode) + "'," +
                                                                "'" + mbook + "'," +
                                                                "'" + mdate + "'," +
                                                                "'" + mvno1 + "'," +
                                                                "'" + mvno2 + "'," +
                                                                "'" + mvno3 + "'," +
                                                                "'" + mpart + "'," +
                                                                "'" + mtot_debit + "'," +
                                                                "'" + mtot_credit + "'," +
                                                                "'" + mbalance + "'," +
                                                                "'" + mcl_type + "'," +
                                                                "'" + mm462index + "'),";
                                                    }
                                                    System.out.print("vvvvvvvvvvvvvvvvvvvvvvv");

                                                    String mfinalquery = (mquery.trim() + mquery2.trim());
                                                    mfinalquery = mfinalquery.substring(0, mfinalquery.length() - 1);

                                                    ArrayQuery.add(mfinalquery);
                                                    ArrayFilename.add(mfilefullname);
                                                }
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }
                                            System.out.print("bbbbbbbbbbbbbbbbbbbbbbb");

                                            return 0;
                                        }
                                        @Override
                                        protected void onPostExecute(Integer a){
                                            System.out.print("nnnnnnnnnnnnnnnnnnnnnnnnnnnn");

                                            if (mall.isLast()) {
                                                System.out.println("333333333333");
                                                jdialog.dismiss();
//                                                trasync();
                                            }
                                        }
                                    }

                                    new m461prepare().execute();
                                }
                            },
                            new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
                                    merror=1;
                                    jdialog.dismiss();
                                    f1.wait_wind("Please check your internet connection", cn);
                                }
                            }) {
                        @Override
                        protected Map<String, String> getParams() throws AuthFailureError {
                            Map<String, String> params = new HashMap<>();
                            params.put("uniqid_guid", co.loggedInUserUniqid);
                            params.put("filename", mfilename);
                            return params;
                        }
                    };
                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(999999999, -1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

                    AppController.getInstance().addToRequestQueue(stringRequest,"m462_req");

                }
            }
            mall.close();
        }
        else{
            f1.wait_wind("Please login first !",cn);
        }
    }

미리 감사드립니다.

매개 변수

파일 길이가 큰 경우 백그라운드에서이 메서드를 실행해야합니다. 이 코드를 시도하십시오.

 @Override
public void onResponse(String  response) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            JSONArray arr = new JSONArray(response);

            int len = arr.length();
            for (int i = 0; i < len; i++) {

               //write your parsing logic here



            }

        }
    }).start();
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관