1. Download our Official Android App: Forums for Android!

Application design for posting fast data to web app server

Discussion in 'Android Development' started by Gajanan Udas, Sep 19, 2017.

  1. Gajanan Udas

    Gajanan Udas Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Sep 18, 2017

    Sep 18, 2017
    2
    0
    5
    I have developed android app that reads car's OBD port data on my Android phone via Bluetooth. I could able to read the complete data in phone but I would like to upload that data from my phone to remote app server. Data coming from car is very fast. How I should use AsyncTask and Threads effectively to avoid frame loss?

    Thanks in advance.
     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Moderator
    Rank:
     #11
    Points:
    1,988
    Posts:
    7,440
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    7,440
    10,723
    1,988
    Male
    Software developer
    South West of England
    Interesting problem. So you would like to stream the data to a remote server, in parallel with reading it from the car?
    This will involve two threads running simultaneously. It's a classic producer/consumer pattern. The two threads will communicate via some shared resource, which is a data structure that can store your items. The data structure absolutely must be synchronized, and thread safe.
    Fortunately Java has a ready-made data structure which is perfect for this situation. It's called BlockingQueue.

    http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/BlockingQueue.html

    This is an interface, so you'll need to use one of the implementing classes. I would go for LinkedBlockingQueue

    http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/LinkedBlockingQueue.html

    which is a FIFO data structure, so it preserves the order of insertion, and removal.

    You producer will be reading data from the car, and the consumer will be taking data out of it and doing the upload. You may want to implement some kind of batch upload, to optimise the performance.
     
    Gajanan Udas likes this.
  3. Gajanan Udas

    Gajanan Udas Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Sep 18, 2017

    Sep 18, 2017
    2
    0
    5
    Thanks a lot! This is really helpful. I will try to implement using this way and will revert in case of any problem. Thanks again.
     

Share This Page

Loading...