Is it possible to interrupt a Java RMI call?

后端 未结 4 2080
旧时难觅i
旧时难觅i 2021-02-08 02:18

We\'re doing some prototyping work and we\'re wondering if it is possible to interrupt a thread that performed an RMI call. If we call interrupt() on this thread, would it throw

4条回答
  •  情歌与酒
    2021-02-08 02:56

    No, interrupt() won't work here, since RMI uses blocking java.io, which is non-interruptable.

    Your options are either to send another RMI call to the server on a separate thread, which asks it to interrupt the processing the call programmatically (assuming the server-side code is performing an interruptible loop of some kind).

    Alternatively perform the original RMI call in a separate thread, which you can then "discard" if required. Using a java.util.concurrant.ExecutorService would seem useful here, since it allows you to submit a task and wait for a finite time for it to complete. The actual RMI call wouldn't be interrupted, but your client program could still continue.

提交回复
热议问题