现在的情况是:
我定时访问一个接口,这个接口需要我传递一个ID,请问有没有什么方法能做到。Timer的schedule这个方法不行啊。有没有其它办法。
急在线等。

解决方案 »

  1.   

    不行 你启动了没有 .start()
      

  2.   

    是不是这个意思..import java.util.Scanner;
    public class helloworld { public static void main(String[] args){
    helloworld hw = new helloworld();
    hw.tThread();
    }
    private void tThread(){
    new Thread(new printThread()).start();
    }
    private class printThread implements Runnable{
    public void run(){
    while(true){
    try{
    Scanner input=new Scanner(System.in);
    int x=input.nextInt();
    tt(x);
    Thread.sleep(5000);
    }catch(Exception e){
    e.printStackTrace();
    }
    }
    }
    private void tt(int i){
    if(i== 0){
     System.exit(0);
    }
    System.out.println("your enter number is:"+i);
    }
    }
    }