Is there a way to get runtime state for a new thread()

I am reading a byte data stream from a serial port. This data stream is from a Bluetooth LE (BLE) Scanner application, so when it’s detecting 10 more BLE devices, and their advertising data packets, we looking at a good amount of data streaming through, which then needs to be parsed.

I found that I had to use noloop() method and only update (loop) when required, to ensure that the app functioned smoothly. This works pretty well, but it’s a little messy if not careful when to loop / not loop etc. especially when I try to add in screen animation using a vector motion dynamics (that’s my end goal).

I then tried creating a separate thread() to process and parse the serial data as received (it uses the polling method inside a while loop). This seems to work pretty well too and sharing of global data between my newly created thread and the main draw thread all seems to work seamlessly.

However, under certain app failures I need to restart and this is where it gets confusing.

So, how do I check the runtime state of my newly created thread.

I see in the JAVA documentation there is such a function, but I am not sure how to include this as the processing function thread() does not return a thread id and so I have no reference.

I basically want to check if the thread has terminated or is still running.

Here’s an example where I simply assume the run state based on observation. I have within my application logic an event which requires the user to click on a button on the screen to continue processing. This seems to terminate my new thread (but I have no way of confirming) and so in this case I simply added in another thread("same function name") upon button click event and my application then continues to process the serial data. I have no idea if this has created a duplicate thread or it simply overrides the old thread with the same name etc.

I am trying to get some visibility here.

Any guidance / tips will greatly appreciated.

Thanks.

G://

hi,
i answer because no one better than me did…(and i will be interested by a pro answer)

however i will say that everything possible in java is usually accessible from processing if you put the right import statement

and i manage this specific problem by having a boolean flag in my thread, false by default, set to true at the beginning and to false at the end… certainly not the best way but…

Thanks for the comment.

Yep, I had considered that option and then thought, without checking more closely, that there was no way my code would’ve triggered the logic condition to exit the while loop within that thread… but no it had. Doh.

At least I now know that I have the option to use the JAVA functions if I chose to by way of using the right import statement.

Thanks to adding in those boolean flags I found another failure condition.

I was trying to share a global arraylist between 2 threads but it seems to terminate my second thread when I want to extract data in the main thread. The 2nd thread adds in new items to the array list while the main thread is trying to display on screen some of the parameters from the array list.

If I used a fixed array size it works.

Is this to be expected?

well… i can confirm two thread works with shared array variables, i didn’t try on arraylist , but i can imagine it’s not fine to have parallel access to it when size vary
anyhow this kind of parallel access can be tricky (i experimented loading and processing data in different thread and get a big mess when upgrade to ssd speed up one thread)

i can t help much on this, it’s a subject by itself but i have no experience on it

if we google “java multiple threads arraylist”, it looks you’re not alone there, may be some good advice to get