Issue
I have a very simple application, the main threat starts 2 AsyncTasks. The 2 AsyncTasks are almost the same, this is the code of one of my AsyncTasks:
private class waitPlayer extends AsyncTask<Integer, Integer, Void> {
@Override
protected Void doInBackground(Integer... params) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
CreateLog.addToLog(e.toString);
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Update your layout here
super.onPostExecute(result);
setCanPlay(true, lastPlayerPlayed);
}
@Override
protected void onProgressUpdate(Integer... progress) {
//progress_p1.setProgress((int) progress[0]);
//progress_p2.setProgress((int) progress[0]);
}
}
The only thing the AsyncTask does is waiting 200ms and after it's done it calls an method. The method will call the AsyncTask again. The other AsyncTask is almost the same, it only waits 3000ms and calls another method.
The problem is that after I added the second AsyncTask my Application got very slow. It freezes a few seconds when the AsyncTasks are running. My Logcat says is full of Garbage Collector notifications.
My phone is not freezing, only the Application. I have about 200mb of free RAM.
01-06 19:26:00.695: W/ActivityThread(25739): Application com.obattech.twoplayergame is waiting for the debugger on port 8100...
01-06 19:26:00.705: I/System.out(25739): Sending WAIT chunk
01-06 19:26:00.710: I/dalvikvm(25739): Debugger is active
01-06 19:26:00.905: I/System.out(25739): Debugger has connected
01-06 19:26:00.905: I/System.out(25739): waiting for debugger to settle...
01-06 19:26:01.105: I/System.out(25739): waiting for debugger to settle...
01-06 19:26:01.305: I/System.out(25739): waiting for debugger to settle...
01-06 19:26:01.505: I/System.out(25739): waiting for debugger to settle...
01-06 19:26:01.705: I/System.out(25739): waiting for debugger to settle...
01-06 19:26:01.910: I/System.out(25739): waiting for debugger to settle...
01-06 19:26:02.110: I/System.out(25739): waiting for debugger to settle...
01-06 19:26:02.310: I/System.out(25739): waiting for debugger to settle...
01-06 19:26:02.510: I/System.out(25739): waiting for debugger to settle...
01-06 19:26:02.710: I/System.out(25739): waiting for debugger to settle...
01-06 19:26:02.910: I/System.out(25739): debugger has settled (1351)
01-06 19:26:03.095: D/libEGL(25739): loaded /system/lib/egl/libEGL_mali.so
01-06 19:26:03.095: D/libEGL(25739): loaded /system/lib/egl/libGLESv1_CM_mali.so
01-06 19:26:03.100: D/libEGL(25739): loaded /system/lib/egl/libGLESv2_mali.so
01-06 19:26:03.100: D/(25739): Device driver API match
01-06 19:26:03.100: D/(25739): Device driver API version: 10
01-06 19:26:03.100: D/(25739): User space API version: 10
01-06 19:26:03.100: D/(25739): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012
01-06 19:26:03.135: D/OpenGLRenderer(25739): Enabling debug mode 0
01-06 19:26:05.680: D/AbsListView(25739): Get MotionRecognitionManager
01-06 19:26:09.415: D/dalvikvm(25739): GC_CONCURRENT freed 92K, 5% free 12473K/13127K, paused 22ms+7ms, total 67ms
01-06 19:26:09.425: D/AbsListView(25739): [unregisterDoubleTapMotionListener]
01-06 19:26:09.425: I/MotionRecognitionManager(25739): .unregisterListener : / listener count = 0->0, listener=android.widget.AbsListView$4@42bfb580
01-06 19:26:12.515: D/dalvikvm(25739): GC_CONCURRENT freed 120K, 6% free 12813K/13575K, paused 3ms+2ms, total 21ms
01-06 19:26:12.515: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 14ms
01-06 19:26:13.665: D/dalvikvm(25739): GC_FOR_ALLOC freed 183K, 7% free 13024K/13895K, paused 17ms, total 18ms
01-06 19:26:15.205: D/dalvikvm(25739): GC_CONCURRENT freed 535K, 9% free 12937K/14151K, paused 2ms+3ms, total 19ms
01-06 19:26:15.205: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 16ms
01-06 19:26:17.095: D/dalvikvm(25739): GC_CONCURRENT freed 536K, 9% free 12904K/14151K, paused 4ms+2ms, total 25ms
01-06 19:26:17.095: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 7ms
01-06 19:26:17.160: D/dalvikvm(25739): GC_CONCURRENT freed 445K, 9% free 12893K/14151K, paused 12ms+12ms, total 35ms
01-06 19:26:19.765: D/dalvikvm(25739): GC_CONCURRENT freed 196K, 7% free 13201K/14151K, paused 5ms+5ms, total 36ms
01-06 19:26:19.765: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 13ms
01-06 19:26:23.260: D/dalvikvm(25739): GC_FOR_ALLOC freed 524K, 9% free 13025K/14279K, paused 18ms, total 18ms
01-06 19:26:26.350: D/dalvikvm(25739): GC_CONCURRENT freed 536K, 10% free 12992K/14279K, paused 3ms+2ms, total 22ms
01-06 19:26:26.350: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 5ms
01-06 19:26:28.290: D/dalvikvm(25739): GC_CONCURRENT freed 548K, 10% free 12948K/14279K, paused 6ms+2ms, total 26ms
01-06 19:26:28.290: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 8ms
01-06 19:26:29.445: D/dalvikvm(25739): GC_CONCURRENT freed 548K, 10% free 12904K/14279K, paused 7ms+2ms, total 30ms
01-06 19:26:29.445: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 7ms
01-06 19:26:29.510: D/dalvikvm(25739): GC_CONCURRENT freed 137K, 8% free 13201K/14279K, paused 3ms+13ms, total 36ms
01-06 19:26:32.065: D/dalvikvm(25739): GC_FOR_ALLOC freed 480K, 9% free 13068K/14279K, paused 17ms, total 17ms
01-06 19:26:36.005: D/dalvikvm(25739): GC_CONCURRENT freed 536K, 9% free 13036K/14279K, paused 14ms+4ms, total 49ms
01-06 19:26:36.005: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 12ms
01-06 19:26:38.665: D/dalvikvm(25739): GC_CONCURRENT freed 547K, 10% free 12992K/14279K, paused 15ms+4ms, total 48ms
01-06 19:26:38.665: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 15ms
01-06 19:26:40.605: D/dalvikvm(25739): GC_CONCURRENT freed 548K, 10% free 12948K/14279K, paused 13ms+2ms, total 32ms
01-06 19:26:40.605: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 6ms
01-06 19:26:43.160: D/dalvikvm(25739): GC_CONCURRENT freed 548K, 10% free 12904K/14279K, paused 13ms+2ms, total 34ms
01-06 19:26:43.160: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 4ms
01-06 19:26:43.225: D/dalvikvm(25739): GC_CONCURRENT freed 533K, 11% free 12805K/14279K, paused 2ms+13ms, total 32ms
01-06 19:26:46.360: D/dalvikvm(25739): GC_CONCURRENT freed 108K, 8% free 13201K/14279K, paused 3ms+2ms, total 22ms
01-06 19:26:46.360: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 8ms
01-06 19:26:47.980: D/dalvikvm(25739): GC_CONCURRENT freed 524K, 9% free 13080K/14279K, paused 12ms+2ms, total 34ms
01-06 19:26:47.980: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 12ms
01-06 19:26:50.405: D/dalvikvm(25739): GC_CONCURRENT freed 547K, 9% free 13036K/14279K, paused 2ms+3ms, total 21ms
01-06 19:26:50.405: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 8ms
01-06 19:26:53.925: D/dalvikvm(25739): GC_CONCURRENT freed 548K, 10% free 12992K/14279K, paused 4ms+4ms, total 38ms
01-06 19:26:53.925: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 18ms
01-06 19:26:55.260: D/dalvikvm(25739): GC_CONCURRENT freed 548K, 10% free 12948K/14279K, paused 8ms+2ms, total 36ms
01-06 19:26:55.260: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 10ms
01-06 19:26:57.080: D/dalvikvm(25739): GC_CONCURRENT freed 548K, 10% free 12904K/14279K, paused 22ms+2ms, total 46ms
01-06 19:26:57.080: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 10ms
01-06 19:26:57.135: D/dalvikvm(25739): GC_CONCURRENT freed 489K, 11% free 12849K/14279K, paused 2ms+12ms, total 29ms
01-06 19:26:58.420: D/dalvikvm(25739): GC_CONCURRENT freed 152K, 8% free 13201K/14279K, paused 13ms+2ms, total 33ms
01-06 19:26:58.420: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 6ms
01-06 19:26:59.565: D/dalvikvm(25739): GC_FOR_ALLOC freed 524K, 9% free 13025K/14279K, paused 18ms, total 19ms
01-06 19:27:02.100: D/dalvikvm(25739): GC_CONCURRENT freed 536K, 10% free 12992K/14279K, paused 2ms+2ms, total 22ms
01-06 19:27:02.100: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 8ms
01-06 19:27:03.685: D/dalvikvm(25739): GC_CONCURRENT freed 547K, 10% free 12948K/14279K, paused 7ms+3ms, total 29ms
01-06 19:27:03.685: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 8ms
01-06 19:27:06.535: D/dalvikvm(25739): GC_CONCURRENT freed 548K, 10% free 12904K/14279K, paused 18ms+3ms, total 52ms
01-06 19:27:06.535: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 9ms
01-06 19:27:06.580: D/dalvikvm(25739): GC_CONCURRENT freed 489K, 11% free 12849K/14279K, paused 2ms+2ms, total 18ms
01-06 19:27:08.065: D/dalvikvm(25739): GC_CONCURRENT freed 152K, 8% free 13201K/14279K, paused 3ms+1ms, total 41ms
01-06 19:27:08.065: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 19ms
01-06 19:27:11.150: D/dalvikvm(25739): GC_FOR_ALLOC freed 526K, 9% free 13025K/14279K, paused 17ms, total 17ms
01-06 19:27:12.600: D/dalvikvm(25739): GC_CONCURRENT freed 545K, 10% free 12982K/14279K, paused 4ms+5ms, total 52ms
01-06 19:27:12.600: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 26ms
01-06 19:27:15.065: D/dalvikvm(25739): GC_CONCURRENT freed 550K, 10% free 12938K/14279K, paused 12ms+3ms, total 37ms
01-06 19:27:15.065: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 6ms
01-06 19:27:15.125: D/dalvikvm(25739): GC_CONCURRENT freed 521K, 11% free 12805K/14279K, paused 3ms+12ms, total 32ms
01-06 19:27:19.575: D/dalvikvm(25739): GC_CONCURRENT freed 110K, 8% free 13201K/14279K, paused 12ms+3ms, total 41ms
01-06 19:27:19.575: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 4ms
01-06 19:27:29.260: D/dalvikvm(25739): GC_FOR_ALLOC freed 534K, 9% free 13028K/14279K, paused 15ms, total 19ms
01-06 19:27:50.315: D/dalvikvm(25739): GC_CONCURRENT freed 546K, 10% free 12957K/14279K, paused 13ms+2ms, total 39ms
01-06 19:27:50.315: D/dalvikvm(25739): WAIT_FOR_CONCURRENT_GC blocked 9ms
01-06 19:27:55.140: D/dalvikvm(25739): GC_CONCURRENT freed 537K, 11% free 12803K/14279K, paused 17ms+3ms, total 36ms
01-06 19:28:05.150: W/jdwp(25739): Debugger is telling the VM to exit with code=1
01-06 19:28:05.150: I/dalvikvm(25739): GC lifetime allocation: 42530 bytes
01-06 19:28:05.510: D/libEGL(27466): loaded /system/lib/egl/libEGL_mali.so
01-06 19:28:05.520: D/libEGL(27466): loaded /system/lib/egl/libGLESv1_CM_mali.so
01-06 19:28:05.520: D/libEGL(27466): loaded /system/lib/egl/libGLESv2_mali.so
01-06 19:28:05.525: D/(27466): Device driver API match
01-06 19:28:05.525: D/(27466): Device driver API version: 10
01-06 19:28:05.525: D/(27466): User space API version: 10
01-06 19:28:05.525: D/(27466): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012
01-06 19:28:05.550: D/OpenGLRenderer(27466): Enabling debug mode 0
01-06 19:28:19.100: D/libEGL(27760): loaded /system/lib/egl/libEGL_mali.so
01-06 19:28:19.105: D/libEGL(27760): loaded /system/lib/egl/libGLESv1_CM_mali.so
01-06 19:28:19.110: D/libEGL(27760): loaded /system/lib/egl/libGLESv2_mali.so
01-06 19:28:19.110: D/(27760): Device driver API match
01-06 19:28:19.110: D/(27760): Device driver API version: 10
01-06 19:28:19.110: D/(27760): User space API version: 10
01-06 19:28:19.110: D/(27760): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012
01-06 19:28:19.165: D/OpenGLRenderer(27760): Enabling debug mode 0
01-06 19:28:48.755: D/AbsListView(27760): Get MotionRecognitionManager
01-06 19:28:50.325: D/dalvikvm(27760): GC_CONCURRENT freed 107K, 6% free 12461K/13191K, paused 3ms+13ms, total 31ms
01-06 19:28:50.330: D/AbsListView(27760): [unregisterDoubleTapMotionListener]
01-06 19:28:50.330: I/MotionRecognitionManager(27760): .unregisterListener : / listener count = 0->0, listener=android.widget.AbsListView$4@42bff9d8
01-06 19:28:55.810: D/dalvikvm(27760): GC_CONCURRENT freed 127K, 6% free 12813K/13575K, paused 3ms+3ms, total 22ms
01-06 19:28:55.810: D/dalvikvm(27760): WAIT_FOR_CONCURRENT_GC blocked 16ms
01-06 19:28:56.915: D/dalvikvm(27760): GC_FOR_ALLOC freed 181K, 7% free 13024K/13895K, paused 18ms, total 18ms
01-06 19:28:58.235: D/dalvikvm(27760): GC_CONCURRENT freed 537K, 9% free 12936K/14151K, paused 2ms+2ms, total 14ms
01-06 19:28:58.235: D/dalvikvm(27760): WAIT_FOR_CONCURRENT_GC blocked 10ms
01-06 19:28:59.130: D/dalvikvm(27760): GC_CONCURRENT freed 527K, 10% free 12793K/14151K, paused 2ms+2ms, total 13ms
01-06 19:29:00.920: D/dalvikvm(27760): GC_CONCURRENT freed 104K, 7% free 13200K/14151K, paused 3ms+3ms, total 31ms
01-06 19:29:00.920: D/dalvikvm(27760): WAIT_FOR_CONCURRENT_GC blocked 13ms
01-06 19:29:06.065: D/dalvikvm(27760): GC_CONCURRENT freed 536K, 9% free 13068K/14279K, paused 5ms+4ms, total 36ms
01-06 19:29:06.065: D/dalvikvm(27760): WAIT_FOR_CONCURRENT_GC blocked 30ms
01-06 19:29:16.625: D/dalvikvm(27760): GC_CONCURRENT freed 547K, 9% free 13027K/14279K, paused 14ms+4ms, total 50ms
01-06 19:29:16.625: D/dalvikvm(27760): WAIT_FOR_CONCURRENT_GC blocked 16ms
01-06 19:29:36.525: D/dalvikvm(27760): GC_CONCURRENT freed 540K, 10% free 12988K/14279K, paused 15ms+4ms, total 56ms
01-06 19:29:36.525: D/dalvikvm(27760): WAIT_FOR_CONCURRENT_GC blocked 21ms
01-06 19:30:06.085: W/IInputConnectionWrapper(27760): showStatusIcon on inactive InputConnection
01-06 19:30:13.920: D/dalvikvm(27760): GC_CONCURRENT freed 549K, 10% free 12926K/14279K, paused 20ms+8ms, total 100ms
01-06 19:30:13.920: D/dalvikvm(27760): WAIT_FOR_CONCURRENT_GC blocked 50ms
01-06 19:30:13.995: D/dalvikvm(27760): GC_CONCURRENT freed 137K, 8% free 13223K/14279K, paused 13ms+3ms, total 44ms
Solution
if you wish to do something in the near future , you can use a handler or a timer .
example :
this will run the runnable in about 2 seconds :
new Handler().postDelayed(new Runnable() {...} , 2000);
asyncTask are used only for small tasks , which you don't care about the order for when they are finished and don't care how many threads are handling them .
as an example , they can be used to download small images from the internet , and be cancelled in case they are used in a listview that is being scrolled too fast .
in any case , we will need to see some more code of yours : what is "setCanPlay" ? and where is the call to the other asyncTask ?
Answered By - android developer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.