import java.util.concurrent.TimeUnit;
public class Test {
public Object obj = new Object();
class T extends Thread{
public T(){}
public void run(){
try{
while(true){
synchronized(obj){
if(...){
doSomeThing1();
TimeUnit.SECONDS.sleep(1);
}else{
doSomeThing2();
TimeUnit.SECONDS.sleep(1);
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}
}