猿问

java timer,如何实现timertask

我想每隔一定时间更新对象属性(调用休息服务)。


我有对象定义和一个带有new和set的类


public class Obj {

    private String data;

    //Getters and setters

}


//A class with the new and sets:


Public class setData{

     public setData{

        Obj o = new Obj();

        o.setdata("hello");

     }

     TimerTask timerTask = new MyTimerTask();

     Timer timer = new Timer(true);

     timer.scheduleAtFixedRate(timerTask, 0, 10*1000);

}


public class MyTimerTask extends TimerTask {


    @Override

    public void run() {

/*

       Here is the question. How can I update the data property of        my object?

       I need to call the rest service, and update. The data              string is on a 

       swing UI.

       */

    }

}

这是问题。如何更新对象的数据属性?我需要致电其余服务,并进行更新。数据字符串在swing UI上。


慕田峪9158850
浏览 165回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答