本帖最后由 woshitianjin 于 2011-11-24 13:52:41 编辑

解决方案 »

  1.   

    你这个就是每隔10秒输出一次吗
    笨拙的代码
    new Thread(new Runnable(){
    public void run(){
    boolean flag=false;
    try {
    while(true){
    while(flag){
    System.out.println("123456789");
    System.out.println(System.currentTimeMillis());
    Thread.sleep(10000);
    }
    if(0==System.currentTimeMillis()%10000){//12点开始输出
    flag=true;
    }else{
    Thread.sleep(1);//1毫秒的判断一次
    }
    }
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    }){}.start();
      

  2.   


    import java.text.SimpleDateFormat;
    import java.util.Date;public class SampleThread { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
            runResult t=new runResult();
            new Thread(t).start();
    }
        
    }
     class  runResult implements Runnable{ @Override
    public void run() {
    // TODO Auto-generated method stub
    while(true){
    try {
    Thread.sleep(10000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    Date dt=new Date();
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    sdf.format(dt);
    System.out.println(sdf.format(dt)+"   123456789");
    }

    }

    }你试试吧
      

  3.   

    if(0==System.currentTimeMillis()%10000){//12点开始输出
    非要12点就改为if(0==System.currentTimeMillis())
      

  4.   

    linux 下  crontab  配置 调用你的类的main方法
      

  5.   

    import java.util.Date;
    import java.util.Timer;
    import java.util.TimerTask;public class Test2 { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Timer timer = new Timer();
    Date date = new Date();
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    Test2 t = new Test2();
    timer.scheduleAtFixedRate(t.new MyTimerTask(), date, 24*60*60*1000);
    } class MyTimerTask extends TimerTask{
    public void run() {
    //new 对象
    }
    }
    }