Dear guys,
Below is the progam I've been writing. It has two threads, one (PanelView) is for displaying the data in the file, and one (DataCreator) is for writing the data into the file. In the middle there is an object to synchronize the two threads. The object has two methods, to read and to write data. To synchronize, right now I uses "guarded block" to toggle between reading and writing the data.
My question is how to convert this "guarded block" style of synchronizing into "lock object" style?
I means, "the Lock.trylock() and Lock.unlock()" style of synchronizing. I've tried to convert it myself, but noluck so far. I am sorry if my phrase is unclear or confusing, but I studied threading mostly from sun's
java tutorial.
Why I need to convert my synchronizing object? Well, firstly I want to study like the rest of the folks here. Secondly, I think that by using "lock object" the synchronizing method will be more effective since the method doesn't wait(). Furthermore, the code line can be reduced.
Thank you for your attention.
And this is the code: