Timeout a task with Java's SwingWorker

前端 未结 4 1337
不知归路
不知归路 2021-01-02 22:52

I am trying to implement a SwingWorker class within my application. Is there a way to set a length of time that after which, the SwingWorker \"times out\"? I

4条回答
  •  梦谈多话
    2021-01-02 23:31

    Why not embed your task within a Runnable, drop it into a new single-threaded ExecutorService and then perform a get() on the resulting Future with an appropriate timeout. That would give you your timeout functionality, since get() will throw an exception if the job doesn't complete in time.

提交回复
热议问题