Issue
In my Android app, I have a arrayList as mentioned below.
Public List<String> prefCoinList = new ArrayList<String>() ;
I will be executing 10 asynchronous task using THREAD_POOL_EXECUTOR as mentioned below.
new asyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, order);
Each asynchronous task will only read the arrayList "prefCoinList" and checks for a particular value.
Question
Will all the 10 Asynchronous task will run without any deadlocks on the arrayList "prefCoinList" ?
Any thread locks / hanging issue will be there ?
If reading the arraylist at same time possible then will each thread get their own copy (or) all thread will wait and read the arraylist when they get their turn ?
Solution
If the list is not modified after construction then you can access it from multiple threads without issue. Each thread will read the single copy of the object.
If the list is modified occasionally then you could use a ReadWriteLock or other access control mechanism.
Answered By - OldCurmudgeon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.