mercredi 6 mai 2015

Fatal spin-on-suspend

I am getting this error after around 45 minutes of my service running, and then it crashes. I see this group of lines in the logcat when it does crash:

Thread pingo = new Thread(new Runnable()
{
    public void run() 
    {

        while (true) 
        {
            if(socket2 != null)//Line 481
            {
            try {
                ping = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket2.getOutputStream())), true);//Line 484
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            ping.write("0000:PING" + "\r\n");

            ping.flush();

            // delay 5 seconds
            try 
            {
                Thread.sleep(5000);
            } catch (InterruptedException e) 
            {
                break;
            }
            }
        }
    }

What this is supposed to do is ping the server every 5 seconds to ensure that the connection is kept alive. Is this the wrong way of doing this? Like I said it takes about 45 minutes or so for the crash to occur..

this is a snippet of the Logcat:

    "Thread-20710" prio=5 tid=25 RUNNABLE
05-06 12:03:04.316: I/dalvikvm(21577):   | group="main" sCount=0 dsCount=0 obj=0x42feb488 self=0x7290da00
05-06 12:03:04.316: I/dalvikvm(21577):   | sysTid=28077 nice=0 sched=0/0 cgrp=apps/bg_non_interactive handle=2098243840
05-06 12:03:04.316: I/dalvikvm(21577):   | state=R schedstat=( 0 0 0 ) utm=1 stm=2 core=3
05-06 12:03:04.316: I/dalvikvm(21577):   at java.nio.ByteBuffer.allocate(ByteBuffer.java:~56)
05-06 12:03:04.316: I/dalvikvm(21577):   at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:44)
05-06 12:03:04.316: I/dalvikvm(21577):   at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:55)
05-06 12:03:04.316: I/dalvikvm(21577):   at com.vli.emsa_mdt.SocketServiceController$2.run(SocketServiceController.java:484)
05-06 12:03:04.316: I/dalvikvm(21577):   at java.lang.Thread.run(Thread.java:841)
05-06 12:03:04.316: I/dalvikvm(21577): "Thread-20707" prio=5 tid=23 RUNNABLE JIT
05-06 12:03:04.316: I/dalvikvm(21577):   | group="main" sCount=1 dsCount=0 obj=0x439c8498 self=0x7d1328a8
05-06 12:03:04.316: I/dalvikvm(21577):   | sysTid=27272 nice=0 sched=0/0 cgrp=apps handle=2098245016
05-06 12:03:04.326: I/dalvikvm(21577):   | state=R schedstat=( 0 0 0 ) utm=20455 stm=7 core=2
05-06 12:03:04.326: I/dalvikvm(21577):   at com.vli.emsa_mdt.SocketServiceController$2.run(SocketServiceController.java:~481)
05-06 12:03:04.326: I/dalvikvm(21577):   at java.lang.Thread.run(Thread.java:841)
05-06 12:03:05.077: W/dalvikvm(21577): threadid=25: spin on suspend #3 threadid=23 (pcf=2)
05-06 12:03:05.077: I/dalvikvm(21577): "Thread-20710" prio=5 tid=25 RUNNABLE

T

Aucun commentaire:

Enregistrer un commentaire