如何将参数传递给Timertask Run方法 [英] How to Pass Arguments to Timertask Run Method
本文介绍了如何将参数传递给Timertask Run方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个方法,我希望它可以安排在以后执行。调度时间和方法的参数取决于用户输入。
I have a method and I want it to be scheduled for execution in later times. The scheduling time and method's arguments depend on user inputs.
我已经尝试过Timers,但我有一个问题。
I already have tried Timers, but I have a question.
怎样才能将参数传递给Java TimerTask run方法?
How could It be possible to pass arguments to Java TimerTask run method ?
TimerTask timert = new TimerTask()
{
@Override
public void run()
{
//do something
}
}
推荐答案
你需要扩展 TimerTask
并创建一个构造函数和/或setter字段..然后设置你想要的值在安排 TimerTask
执行之前。
You will need to extend the TimerTask
and create a constructor and/or setter fields.. Then set the values you want before scheduling the TimerTask
for execution.
这篇关于如何将参数传递给Timertask Run方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文