Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How can I have a thread continually process an ArrayList?

$
0
0
Hello! I have a thread in android that is supposed to do something with all of the elements in an arraylist until there are no more elements left, but when more elements are added do the same thing, over and over until the program is done. This is what I am doing so far:
private volatile ArrayList<StrokeQueueEntry> queue;
	public void run() {
		//Process items in the queue
		if(queue.size()>0){
			while(queue.size()>0){
                                //Lots of code here basically to process & remove the first element in the list
				Thread.yield();
			}
		}
		Thread.yield();
	}



What I am wondering is if this is the best way to do it? I am not an expert with Java or concurrency yet,

Sorry for the multipost, I pressed enter by accident and I cannot edit my post, but this is being used so the UI thread in my android app wont hang. If anyone knows a better way of doing this I would love to hear it. As far as i know the thread is doing its job and the UI thread isnt hanging, but I am not very confident if this is how I am supposed to do it?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>