Java在正常函数上实现调度程序错误

Java在正常函数上实现调度程序错误,java,scheduled-tasks,Java,Scheduled Tasks,目前,我有一个java应用程序,我从主应用程序调用函数,然后在主应用程序中完成所有操作。下面是我的代码片段。因此,我需要及时运行函数调用,并阅读有关调度程序的信息。因此,我尝试在我的主函数中实现它,并得到错误:“void”类型在这里不允许final ScheduledFuture timeHandle=scheduler.scheduleAtFixedRate(ws1TI(),0,10)此问题的任何解决方案“ 公共类ws1TI { 公共静态无效ws1TI() { 尝试 { SOAPConnect

目前,我有一个java应用程序,我从主应用程序调用函数,然后在主应用程序中完成所有操作。下面是我的代码片段。因此,我需要及时运行函数调用,并阅读有关调度程序的信息。因此,我尝试在我的主函数中实现它,并得到错误:“void”类型在这里不允许
final ScheduledFuture timeHandle=scheduler.scheduleAtFixedRate(ws1TI(),0,10)此问题的任何解决方案“

公共类ws1TI
{
公共静态无效ws1TI()
{
尝试
{
SOAPConnectionFactory SOAPConnectionFactory=SOAPConnectionFactory.newInstance();
SOAPConnection-SOAPConnection=soapConnectionFactory.createConnection();
String url=“http://*********.asmx?WSDL”;
SOAPMessage soapResponse=soapConnection.call(createSOAPRequest(),url);
打印soapResponse(soapResponse);
更新知识库();
}
捕获(例外e)
{
e、 printStackTrace();
System.err.println(例如toString());
}
}
公共静态void main(字符串[]args)
{
ScheduledExecutorService scheduler=执行者。newSingleThreadScheduledExecutor();
final ScheduledFuture timeHandle=scheduler.scheduleAtFixedRate(ws1TI(),0,10);
}    
}

scheduleAtFixedRate
应接收一个值,而不是一个无效值。例如,您可以将
ws1TI
函数转换为
可运行的
,如下所示:

public class ws1TI {
    public static class WS1TI implements Runnable {
        @Override
        public void run() {
            try {
                 SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
                 SOAPConnection soapConnection = soapConnectionFactory.createConnection();
                 String url = "http://*********.asmx?WSDL";
                 SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
                 printSOAPResponse(soapResponse);
                 updateAcknoledgement();
            }
            catch (Exception e) {
                 e.printStackTrace();
                 System.err.println(e.toString());
            }
        }
    }

    public static void main(String[] args) {
        ScheduledExecutorService scheduler =
            Executors.newSingleThreadScheduledExecutor();   
        final ScheduledFuture<?> timeHandle = 
            scheduler.scheduleAtFixedRate(new WS1TI(), 0L, 10L, TimeUnits.MINUTE); 
    }
}
公共类ws1TI{
公共静态类WS1TI实现可运行{
@凌驾
公开募捐{
试一试{
SOAPConnectionFactory SOAPConnectionFactory=SOAPConnectionFactory.newInstance();
SOAPConnection-SOAPConnection=soapConnectionFactory.createConnection();
String url=“http://*********.asmx?WSDL”;
SOAPMessage soapResponse=soapConnection.call(createSOAPRequest(),url);
打印soapResponse(soapResponse);
更新知识库();
}
捕获(例外e){
e、 printStackTrace();
System.err.println(例如toString());
}
}
}
公共静态void main(字符串[]args){
ScheduledExecutorService计划程序=
Executors.newSingleThreadScheduledExecutor();
最终计划的未来时间句柄=
scheduleAtFixedRate(新WS1TI(),0L,10L,TimeUnits.MINUTE);
}
}

我尝试了你的方法我不明白为什么需要两个公共类ws1TI,其中一个是静态的?其次,我得到了所需的错误:Runnable,long,long,TimeUnit found:ws1TI,int,int原因:实际参数列表和形式参数列表的长度不同1错误第一个参数是一个
Runnable
的实例,其中包含你想要运行的代码最后一个,我确实缺少了,
TimeUnits
的一个实例,它解释了如何解释您提供的速率。我用分钟编辑了相应的答案。事实上,我以前也尝试过,现在又一次出现此错误符号:可变时间单位位置:类ws1TI 1错误。我必须更改此公共静态类ws1TI吗实现Runnable{classname到其他对象是不是我们在公共类ws1TI{之外放置了一个类。Runnable类必须覆盖run函数调用的所有函数吗?
public class ws1TI {
    public static class WS1TI implements Runnable {
        @Override
        public void run() {
            try {
                 SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
                 SOAPConnection soapConnection = soapConnectionFactory.createConnection();
                 String url = "http://*********.asmx?WSDL";
                 SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);
                 printSOAPResponse(soapResponse);
                 updateAcknoledgement();
            }
            catch (Exception e) {
                 e.printStackTrace();
                 System.err.println(e.toString());
            }
        }
    }

    public static void main(String[] args) {
        ScheduledExecutorService scheduler =
            Executors.newSingleThreadScheduledExecutor();   
        final ScheduledFuture<?> timeHandle = 
            scheduler.scheduleAtFixedRate(new WS1TI(), 0L, 10L, TimeUnits.MINUTE); 
    }
}