在 java 中的线程内放置一个主函数参数

Put a main function args inside the thread in java

我在 java 中遇到线程问题。 这是我的 class 实现线程:

public class SensorAddClient extends Thread implements Runnable {
String[] args = new String[3];
@Override
public void run(){
try {
    SensorClient.main(args);//this is the main function i wanna get executed on my args
} catch (IOException e) {
    e.printStackTrace();
} catch (JSONException e) {
    e.printStackTrace();
}}

然后我在需要激活线程时使用接下来的两行来调用它:

SensorAddClient cl = new SensorAddClient(); cl.start();

我必须启动一个线程,它的 运行 只需要调用一个特定的 class,它使用 args 执行,所以我调用 class 的主要函数,是吗有什么方法可以使我调用的 class 的主要功能以我想要的参数执行? 那么我可以把元素放在上面吗: 字符串[] args = 新字符串[3];在执行线程的 运行 之前?那可能吗 ? 任何帮助将不胜感激,提前谢谢你:)

创建构造函数并在其中添加值:

public class SensorAddClient extends Thread implements Runnable {
String[] args = new String[3];

public SensorAddClient(String[] args) {

 this.args = args;

}
@Override
public void run(){
try {
    SensorClient.main(args);//this is the main function i wanna get executed on my args
} catch (IOException e) {
    e.printStackTrace();
} catch (JSONException e) {
    e.printStackTrace();
}}