The following Function is executing in its own thread:
private void doSendData()
{
try {
//writeToFile(); // just a temporary location of a c
The above are correct. You can use a synchronized block of code. Or you can create what they call a mutex. A mutex can actually be any object. Lots of people just use Object itself as a mutex. Then you can lock on the mutex. Any threads wanting to get access must wait for thread holding the mutex to release it.
There was also a suggestion by Apocalisp. I would also recommend that you look at the java.util.concurrent package.