I am trying to run 4 threads in parallel, but failing.
I have tried using synchronous wait()
and notify()
CyclicBarrier
Thre
Can we run 4 thread parallel i.e. at the same time in Android ??
Yes, you can run 4 thread in parallel. Adding more threads usually helps, but at some point, they cause some performance degradation. But 4 threads will not cause an issue.
Issues: I am not able to run thread parallel i.e. 1st Threads runs : 4 times, 2nd 3rd n 4th only 1 time. How to make it run (Tried using mentioned threads but unsuccess to run all thread parallel) parallel?
If your goal is simply to have all threads actively processing, I suggest looking at Java thread pools (and Executors more generally).
android support MULTI-THREADING? If yes how multi-threading works in android??
Yes, Android supports Multithreading. The most preferred way of implementing it(other than Thread Pool and Executor) is AsyncTask
AsyncTask allows you to implement doInBackground()
, where your thread can crank away at its task. This is similar to the functionality you'd get from Thread
.
The real magic happens when you override onPreExecute()
and onPostExecute()
, which are both executed on the UI thread. This should keep you from getting messages about your Activity not being attached.
this answer contains a small code example for AsyncTask
that could get you started.
Also, have a look at Handlers in Android
Edit- What I found during my research is that recording, sending and receiving audio all are quite interactive processes and they require sync and IO resources. The best possible solution for it could be, you can create separate AsyncTask for each of the operations so that each operation is performed in its separate AsyncTask.