The following Function is executing in its own thread:
private void doSendData() { try { //writeToFile(); // just a temporary location of a c
In general when you have multi-threaded program in Java you need to lock the shared variable by using synchronized (key-word) then in anytime just one thread can access the shared memory.