Thursday, 22 August 2013

Is it a good way to use java.util.List as a buffer?

Is it a good way to use java.util.List as a buffer?

I have the main process and a thread running together. The main process
receives all the incoming UDP messages and put it into a List.
Then the thread is intended for processing those UDP messages.
However when I tried the following snippet inside the thread
int count = 0;
while(true)
{
if (buffer.size()>count)
{
System.out.println("Processing "+buffer.get(count));
counter++;
}
}
the thread doesn't seem to work well.
By the way, buffer is
List<String> buffer = new ArrayList<String>();
and it is where the main process puts all the received UDP messages
any advice guys? :-)

No comments:

Post a Comment