I have a java program which has two threads : a read thread and a write thread. The write thread takes instructions from user to be done and writes it in the text file. The read thread reads the instructions in the text file and executes them. If an instruction is successfully executed it is to be deleted from text file so that it is not executed again.
What is the best way to achieve this?
I am thinking of using append during write thread and then use a temp file to create a new text file during read thread so that I can remove the instructions that have been executed.
Do I need to use some type of locks so that data remains synchronized during read/write operations. Also a temp file approach is fine or should I use random access?
Thanks