change thread sleep to 1 and add writeThread