[OFFEN] The application may be doing too much work on its main thread

B

bronsetin

Neues Mitglied
0
Hallo zusammen,
meine App stürzt nach ein paar Minuten immer ab:
I/Choreographer: Skipped 83 frames! The application may be doing too much work on its main thread.
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/art: Background sticky concurrent mark sweep GC freed 76356(9MB) AllocSpace objects, 2(64KB) LOS objects, 33% free, 19MB/29MB, paused 60.517ms total 266.319ms
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/Choreographer: Skipped 75 frames! The application may be doing too much work on its main thread.
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/art: Background sticky concurrent mark sweep GC freed 77585(8MB) AllocSpace objects, 2(64KB) LOS objects, 26% free, 21MB/29MB, paused 68.271ms total 561.163ms
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/art: Background partial concurrent mark sweep GC freed 94995(11MB) AllocSpace objects, 2(60KB) LOS objects, 40% free, 21MB/35MB, paused 72.944ms total 772.088ms
I/Choreographer: Skipped 94 frames! The application may be doing too much work on its main thread.
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/art: Background sticky concurrent mark sweep GC freed 107822(12MB) AllocSpace objects, 2(60KB) LOS objects, 32% free, 23MB/35MB, paused 79.858ms total 919.730ms
I/Choreographer: Skipped 93 frames! The application may be doing too much work on its main thread.
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
W/art: Suspending all threads took: 18.953ms
I/System: core_booster, getBoosterConfig = false
I/art: Background partial concurrent mark sweep GC freed 109349(12MB) AllocSpace objects, 4(224KB) LOS objects, 40% free, 23MB/38MB, paused 246.309ms total 2.735s
I/Choreographer: Skipped 423 frames! The application may be doing too much work on its main thread.
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
W/art: Suspending all threads took: 17.615ms
I/art: Background sticky concurrent mark sweep GC freed 134974(16MB) AllocSpace objects, 2(64KB) LOS objects, 36% free, 24MB/38MB, paused 270.250ms total 3.578s
I/Choreographer: Skipped 539 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 538 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 30 frames! The application may be doing too much work on its main thread.
I/art: Background partial concurrent mark sweep GC freed 138549(16MB) AllocSpace objects, 3(140KB) LOS objects, 39% free, 24MB/40MB, paused 290.807ms total 3.725s
I/Choreographer: Skipped 515 frames! The application may be doing too much work on its main thread.
I/art: Background sticky concurrent mark sweep GC freed 105652(12MB) AllocSpace objects, 2(60KB) LOS objects, 38% free, 25MB/40MB, paused 191.503ms total 690.866ms
I/Choreographer: Skipped 540 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 32 frames! The application may be doing too much work on its main thread.
I/art: Background sticky concurrent mark sweep GC freed 103959(12MB) AllocSpace objects, 2(64KB) LOS objects, 35% free, 26MB/40MB, paused 326.184ms total 1.054s
I/Choreographer: Skipped 608 frames! The application may be doing too much work on its main thread.
I/art: Background sticky concurrent mark sweep GC freed 103823(12MB) AllocSpace objects, 2(60KB) LOS objects, 30% free, 28MB/40MB, paused 129.525ms total 1.708s
I/Choreographer: Skipped 762 frames! The application may be doing too much work on its main thread.
I/art: Background partial concurrent mark sweep GC freed 125854(13MB) AllocSpace objects, 3(144KB) LOS objects, 35% free, 28MB/44MB, paused 174.592ms total 3.385s
I/Choreographer: Skipped 765 frames! The application may be doing too much work on its main thread.
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
W/art: Suspending all threads took: 33.054ms
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/System: core_booster, getBoosterConfig = false
I/art: Background sticky concurrent mark sweep GC freed 165622(20MB) AllocSpace objects, 4(124KB) LOS objects, 27% free, 32MB/44MB, paused 502.010ms total 13.067s
I/Choreographer: Skipped 876 frames! The application may be doing too much work on its main thread.
I/Choreographer: Skipped 41 frames! The application may be doing too much work on its main thread.
I/System: core_booster, getBoosterConfig = false
I/Choreographer: Skipped 833 frames! The application may be doing too much work on its main thread.
W/libc: pthread_create failed: clone failed: Try again
W/art: Throwing OutOfMemoryError "pthread_create (1040KB stack) failed: Try again"
I/Process: Sending signal. PID: 25561 SIG: 9
Disconnected from the target VM, address: 'localhost:8618', transport: 'socket'

Im Anhang habe ich mal den Quellcode, vllt. kann mir ja wer weiterhelfen
 

Anhänge

  • MenueActivity.txt
    33,1 KB · Aufrufe: 148
Hallo Bronsetin,

du hast eindeutig MemoryLeaks , also scheinst du irgendwo benötigten Speicher nicht freizugeben.
Lt Fehlermeldung ackert dein UI wie blöde.

Ich habe mir eben deinen SourceCode geladen und nimm es mir nicht übel :
Das Durchforsten von Diesem sprengt den Rahmen einer Forenhilfe, zumal ein wenig mehr OOP orientiert,
die Suche schon ein wenig erleichtern würde. (Spaghetti Code)
(Vielleicht hat ja jemand Anderes die Zeit dazu )


Gehe nach dem Ausschlussverfahren vor - Dann bekommst du auch recht schnell selbst den Überltäter.

Ich würde mal bei deinem Poll-Timer anfangen - der könnte auch gut Listener/Callback-orientiert sein
 
Zuletzt bearbeitet:
Wenn ich diese Funktion nicht aufrufe, dann steigt der Arbeitsspeicher nicht:
private void statusMeldung(final int id, final String text, final String Von) {

System.gc();
try {
requestQueue = Volley.newRequestQueue(getApplicationContext());
} catch (Exception e) {
// This will catch any exception, because they are all descended from Exception
appendLog(Bereich + " -> " + Abteilung + " statusMeldung 1_1: " + e.getMessage());

}


StringRequest request = new StringRequest(com.android.volley.Request.Method.POST, showSQLTest2, new com.android.volley.Response.Listener<String>() {
@override
public void onResponse(String response) {

String test = response.toString();
if (test.contains("[]") == true)
{
//Meldung
appendLog(Bereich + " -> " + Abteilung + " statusMeldung 1_2");
tg.startTone(ToneGenerator.TONE_CDMA_INTERCEPT);

appendLog(Bereich + " -> " + Abteilung + " statusMeldung 1_3");

//Bildschirm einschalten
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire(20000);

Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setData(Uri.parse("www.xxx.com"));
PendingIntent contentIntent = PendingIntent.getActivity(MenueActivity.this, 0, notificationIntent, 0);

Notification notification = new NotificationCompat.Builder(MenueActivity.this)
.setCategory(Notification.CATEGORY_PROMO)
.setContentTitle("Warnung")
.setContentText(text + " -> " + Von)
.setSmallIcon(R.mipmap.xxx_logo4)
.setAutoCancel(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
//.addAction(android.R.drawable.ic_menu_view, "View details", contentIntent)
.setContentIntent(contentIntent)
.setPriority(Notification.PRIORITY_HIGH)
.setLights(Color.GREEN, 2000, 2000)
.setVibrate(new long[]{2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000}).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
int notification_id = 0;
notificationManager.notify(notification_id, notification);

statusMeldungChangeState(id, IPAdresse(), 1);
appendLog(Bereich + " -> " + Abteilung + " statusMeldung 1_5");
}
requestQueue = null;
}
}, new com.android.volley.Response.ErrorListener() {
@override
public void onErrorResponse(VolleyError error) {
TestString = "asd";
}
}) {

@override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("ID", Integer.toString(id));
parameters.put("IP", IPAdresse());

return parameters;
}
};
appendLog(Bereich + " -> " + Abteilung + " statusMeldung 1_6");
requestQueue.add(request);
appendLog(Bereich + " -> " + Abteilung + " statusMeldung 2");

}
 
a) Gibt es denn einen Grund , warum du den GarbageCollector tötest ?
So eine Brutalität habe ich nirgends in meinen Apps, braucht man auch nicht an dieser Stelle.
b) Warum ist dein Volley ohne Listener ?
c) Warum "append" - lass den auch mal weg
 
a) Habe ich herausgenommen, war ein versuch welcher aber leider auch nicht erfolgreich war
b) Brauche ich den unbedingt einen Listner?
c) Was meinst du damit, append war eine Testfunktion von mir wo ich ein kleines LogFile geschrieben hatte, habe ich auch mal herausgenommen

Ich habe mal alles unnötige weggelassen, der Arbeitsspeicher steigt aber trotzdem:
private void statusMeldung(final int id, final String text, final String Von) {
try {
requestQueue = Volley.newRequestQueue(getApplicationContext());
} catch (Exception e) {
// This will catch any exception, because they are all descended from Exception

}
StringRequest request = new StringRequest(com.android.volley.Request.Method.POST, showSQLTest2, new com.android.volley.Response.Listener<String>() {
@override
public void onResponse(String response) {

String test = response.toString();
if (test.contains("[]") == true)
{

}
requestQueue = null;
}
}, new com.android.volley.Response.ErrorListener() {
@override
public void onErrorResponse(VolleyError error) {
TestString = "asd";
}
}) {
@override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("ID", Integer.toString(id));
parameters.put("IP", IPAdresse());

return parameters;
}
};
requestQueue.add(request);
}


Es liegt wohl an der globalen Variable:

public class MenueActivity extends AppCompatActivity {
RequestQueue requestQueue;
...

Wenn ich diese jedoch lokal in der Funktion deklariere, spring mir das Programm nicht mehr in public void onResponse(String response)
 
Zuletzt bearbeitet:
Hallo bronsetin,

ich hatte ja schon Eingangs erklärt , dass dein Code unübersichtlich ist und eigentlich nicht
einem ordentlichen Aufbau nahe kommt.

Das hat auch nichts mit lokal/public zu tun - ich vermute stark, das dein Ablauf nicht stimmt
und den können wir hier nicht nachvollziehen .

Du arbeitest mit Timer , Http Requests und UI Zugriffen - aber wartest nicht auf die Ereignisse mittles Listener.
Das geht in der Regel schief , der Ablauf muss schon koordiniert sein und man darf nicht drauf "Hoffen" dass alles
ordentlich erledigt ist.
Zum Beispiel haust du mitten rein den Tongenerator - der gehört eigentlich Asynchron in einen Thread.

Entwurschtel mal deine MainActivity und bilde daraus objektorientiere Klassen.
Und vor allem , baue Listener ein und warte darauf das z.b. ein HTTP request ordentlich abgeschlossen ist.

Bei Java kommt es auf das richtige Timing an, mehr als z.b. unter C/ C++

Gibt der UI grundsätzlich Luft zu arbeiten und baller die nicht zu

Zitat aus deinem Errorlog :
I/Choreographer: Skipped 833 frames! The application may be doing too much work on its main thread.
W/libc: pthread_create failed: clone failed: Try again


Arbeite - wie oben erwähnt mit Listener und oder Threads / AsyncTasks - erst dann kann das auch alles freilaufen
 
Zuletzt bearbeitet:
Hallo @bronsetin, der Problem liegt nicht in Request selber, sondern in den Spektakel, welches du in den Methoden onResponse(...) veranstaltest.

Der Code in der Methode wir erst aufgerufen, wenn der nebenläufige Teil der Internetkommunikation fertig ist. Sprich der Teil läuft im Main Thread. Dort veränderst du das Layout, und die CPU kommt mit der Anzahl der Rechenoperationen nicht mehr mit, da du zu häufig die Methode in kurzer Zeit aufrufst. Außerdem belegen die Abarbeitung der vielen Methodenaufrufe zu viel Speicher.

Am besten lädst alle Daten in einem Volley Request und verarbeitest die Jason danach in einem Task.
 
  • Danke
Reaktionen: swa00
Erstmal danke für die zahlreichen Tipps, ich habe mich jetzt mal daran versucht dies asynchron via AsyncTask zu machen:
package com.example.XXXt.de.tp_app_mes;

import android.content.Context;
import android.os.AsyncTask;

import com.android.volley.AuthFailureError;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import java.util.HashMap;
import java.util.Map;

/**
* Created by XXXT on 10.11.2017.
*/

class HintergrundAbfragen extends AsyncTask<String, Void, Integer> {
private Context context;

String s = "";
private com.example.XXXt.de.tp_app_mes.OnTaskCompleted taskCompleted;

public HintergrundAbfragen(Context context) {
this.context = context;
}

@override
protected void onPreExecute() {
// Your code
}


protected Integer doInBackground(String... urls) {

int count = urls.length;
long totalSize = 0;
String Bereich = null, Abteilung = null, showSQLTest = null;

for (int z = 0; z < count; z++) {
if (z == 0) {
Bereich = urls[z].toString();
}
if (z == 1) {
Abteilung = urls[z].toString();
}
if (z == 2) {
showSQLTest = urls[z].toString();
}
}


RequestQueue requestQueue = Volley.newRequestQueue(context.getApplicationContext());
final String finalBereich = Bereich;
final String finalAbteilung = Abteilung;

StringRequest request = new StringRequest(com.android.volley.Request.Method.POST, showSQLTest, new com.android.volley.Response.Listener<String>() {
@override
public void onResponse(String response) {
s = "Fertig";
}
}, new com.android.volley.Response.ErrorListener() {
@override
public void onErrorResponse(VolleyError error) {
}
}) {

@override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("BEREICH", finalBereich);
parameters.put("ABTEILUNG", finalAbteilung);
return parameters;
}
};
requestQueue.add(request);
return 1;
}


protected void onPostExecute() {
//hier darf man die GUI updaten
taskCompleted.onTaskCompleted(s);
}

public interface OnTaskCompleted {
void onTaskCompleted(String response);
}

}


Bin dabei nach diesem Tutorial vorgegangen:
AsyncTask Implementation using callback interface

Leider erreiche ich die Funktion onPostExecute nie, sieht von euch einer einen Fehler den ich mache?
In den onResponse vom StringRequest wird reingesprungen, wie gebe ich jetzt aber weiter dass der Request auch fertig ist?
 

Ähnliche Themen

S
Antworten
0
Aufrufe
593
Sergio13
S
W
  • waltsoft
Antworten
3
Aufrufe
723
waltsoft
W
W
  • waltsoft
Antworten
4
Aufrufe
938
waltsoft
W
Zurück
Oben Unten