目前,我有我的java应用程序,我从主函数中调用了该函数,然后所有的工作都完成了。下面是我的代码片段。所以我需要及时运行函数的调用并阅读有关调度程序的信息。所以我尝试在我的主函数中实现它并收到错误:此处不允许“void”类型final ScheduledFuture<?> timeHandle = scheduler.scheduleAtFixedRate(ws1TI(), 0, 10);
这个问题有什么解决办法吗“?
public class ws1TI
{
public static void ws1TI()
{
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(ws1TI(), 0, 10);
}
}
最佳答案
scheduleAtFixedRate
应收到 Runnable
,不是空值。例如,您可以将 ws1TI
函数转换为 Runnable
,如下所示:
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);
}
}
关于Java 在正常功能上实现调度程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27753085/