我想每隔一定時間更新對象屬性(調(diào)用休息服務)。我有對象定義和一個帶有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. */ }}這是問題。如何更新對象的數(shù)據(jù)屬性?我需要致電其余服務,并進行更新。數(shù)據(jù)字符串在swing UI上。
java timer,如何實現(xiàn)timertask
慕田峪9158850
2021-04-09 14:15:52