class TextThread implements Runnable {
private String text;
private Thread thread;
private Object obj;
public TextThread(String text,Object obj) {
this.text = text;
this.obj = obj;
thread = new Thread(this);
thread.start();

}
public void run() {
synchronized (obj){
for (int i = 0; i < 4 ;i++){
System.out.println(text+":"+i);
try {
thread.sleep(500);
}
catch (InterruptedException e){}
}
}
}
}public class ThreadExample1 {
public static void main(String [] args) {
ThreadExample1 t = new ThreadExample1();
new TextThread("TypeText1",t);
new TextThread("TypeText1",t);
}}