I am working on the j2me appln.The appln syncs data to the server depending on the dates which is selected and this data is saved in the rms files.
Currently my requirement is that, the application should syncs all the saved data on click of one command and also the data should be synced sequentially.
For ex : I am syncing the data of 18,19,20 and 21. Now I want that until and unless the server sends an acknowledgement for 18 th the 19th should not be uploaded.
By this I mean t5hat,19th thread should be kept on hold until and unless I receive the ack for 18 thread from server
You could wait for the threads to reach each other at the same point before proceeding to the network connection, checking their progress with some volatile booleans.
It sounds like a buffer might be useful, something to hold the data as it completes, perhaps a Hashtable or a custom wrapper object, so you can organize it.
There are sleep() and join() methods in the Thread class. These might help if you don't mind blocking a thread for a while or ending it. Otherwise, if you intend to continue using these threads afterwards, these Thread methods probably won't help.
You can declare a method synchronized to run a method one thread at a time, but this blocking is slow, or you could use a synchronized block, with a locking reference using a private object reference or perhaps the current object's lock (this keyword), within a method to atomically block just a small section of method which allows other threads to run between the lines before/after the non-synchronized calls.