I have a list of elements sent through a server, I have a local copy of that list each time the server calls my client's update method.

The update method itself checks if the newly sent list is identical to the local copy, if not, modify the local copy. This means that if on the server, the element is no longer present, then it should be removed from the local copy.

The problem arises when the last element disappears on the server: once it does, the server stops calling the update method. This means that the local copy is left with a single element until the update method is called again, since it only gets called while the server has data to send.

Now I can't change the server architecture or the fact that it doesn't call the method when the list is empty. I can only modify the client side.

I've been experimenting with threads on my client to have some sort of thread running in parallel to clear the list if the list has not been updated in a while. This has not been working correctly or effectively, and I seem to get random results that can change completely just by changing how often the thread runs.

My main problem arises because I can't seem to find an effective way to tell if I am actively receiving data or not. I also can't seem to find a way to check if a thread is currently blocked or not.

Any ideas on how I can approach this problem? I'm not very good with threading/multi-threading and I've been bashing my head against this wall for a while now.

Without direct notification that the server is done/doesn't contain data, you need to leverage some other requirement or condition that can be used as a hint to clear the final element. You mention the server might send an update with the same data, does this mean that there is a requirement for it to update at a regular scheduled interval?
–
Tim BenderJun 22 '10 at 5:48

The server is receiving data in certain situations, lets say radar data, for instance. When it isn't receiving any though, it will not update, but as long as something is triggering said radar, the server will be sending data.
–
KyleJun 22 '10 at 6:27

2 Answers
2

Seeing some code would help in providing a more specific answer, but if the approach you've pursued works on a conceptual level, you could take a look at Java's Timer class and create a TimerTask that calls a method that checks when the list was last updated and clears it if appropriate.

I had just tried my own sort of timer thread and it seemed to be doing the job, but bogging up my CPU by 100% :/ I'm going to try the java Timer class, it probably does it more efficiently then I can.
–
KyleJun 22 '10 at 6:28

Hah okay, the timer class was much more efficient! What I was doing before is that I started the thread inside the update method, now I start the timer outside and then close it separately and everything works dandy. Thanks!
–
KyleJun 22 '10 at 7:47