extends TimerTask to create your own task
import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.TimerTask; class MyTask extends TimerTask { private DataOutputStream out; public MyTask(OutputStream dest) { out = new DataOutputStream(dest); } public void run() { try { out.writeInt(1); out.writeUTF("asdf"); } catch (IOException e) { e.printStackTrace(); } } }