Unexpected behavior of the same methods on different threads

My initial question: Android GraphView project will freeze with realtime update . In this one, I asked about the possible concurrency in a 3-graph UI thread. On the memory allocation graph, it looks like this:

enter image description here

I was getting data directly from my ProcessThread

main activity and passing it using onEventMainThread

from the EventBus

library back to GraphFragment

. All transmitted data comes from ProcessThread

, which collects data from the Bluetooth listening service and then continues to receive meaningful digits.

My idea was to check if this happens with a test thread that only generates data and sends it to onEventMainThread

. Since this also causes some errors, I was forced to ask another question: Difficulty understanding complex multithreading in an Android app . After a while, I got a great answer from @AsifMujteba explaining that my test thread is too fast.

Knowing that I was able to go back to my main problem and my real topic to check if all the timings were correct. As I said, there is a lot going on, so being fast is not a problem (however, I added this same mechanization for validation if data is not sent quickly). I would be more worried about slowing down this thread.

My current one onEventMainThread

looks like this:

public void onEventMainThread(float[] data) {
            mSeries1.appendData(new DataPoint(counter,data[0]),true,100);
            mSeries1.appendData(new DataPoint(counter,data[1]),true,100);
            mSeries1.appendData(new DataPoint(counter,data[2]),true,100);
            counter++;
        }

      

Unfortunately, when I went back to the beginning, the problem appeared again. After a lot of testing, I can say that the data looks like it is being sent correctly. I checked it with two markers:

public void onEventMainThread(float[] data) {
                Log.d("LOG","marker1");
                mSeries1.appendData(new DataPoint(counter,data[0]),true,100);
                mSeries1.appendData(new DataPoint(counter,data[1]),true,100);
                mSeries1.appendData(new DataPoint(counter,data[2]),true,100);
                counter++;
                Log.d("LOG","marker2");
            }

      

Logcat messages are displayed correctly. Unfortunately, the error appears, although the submission looks the same as in my test thread:

if((System.currentTimeMillis()-start)>10) {
    values[0] = (float) getRandom();
    values[1] = (float) getRandom();
    values[2] = (float) getRandom();
    EventBus.getDefault().post(values);
    start = System.currentTimeMillis();
}

      

What else I am sure the data is being sent correctly all the time, because when I tested another snippet with OpenGL rendering everything works.

So, let's summarize everything:

When sending values ​​to a chunk using EventBus

from one (very simple) stream, everything works fine, and sending from another (more complex) stream ends up freezing the display and displaying the memory allocation graph. It is important to know that if one thread is running, then the second is commented out.

Can someone please advise me what could be the problem here? Or what should I check more?

EDIT

I did another test, commenting out everything about adding series data, leaving only Log.d()

and no error came up. Interestingly, blocking (or freezing) updates to the graph does not affect the interface itself, so I can still press all buttons, etc.

0


source to share


1 answer


Have you tried using a custom eventbus rather than a standard one? I had a similar problem today and fixed it by creating my own generic pipe with a separate ThreadPool and it worked like a charm.



0


source







All Articles