Java 在正常功能上实施调度程序错误

Java implementing scheduler errors on normal function

目前我有我的 java 应用程序,我在其中调用了 main 中的函数,然后在其中完成了所有操作。以下是我的代码片段。所以我需要及时运行函数调用并阅读有关调度程序的信息。所以我试图在我的主要功能中实现它并得到错误:'void' type not allowed here final ScheduledFuture<?> timeHandle = scheduler.scheduleAtFixedRate(ws1TI(), 0, 10); Any solution to this issue "?

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); 
    }
}