title: How to forcibly cancel a background task in Scala or Java?
body: <p>I'm using a library that has a long-running RPC <code>longRunningCall</code>. Right now I'm submitting Java futures to a thread pool like:</p>
  <pre><code>val myFuture = myPool.submit(() =&gt; { someLibrary.longRunningCall() })
  </code></pre>
  <p>Unfortunately <code>longRunningCall</code> can hang indefinitely. I first tried waiting for the Future like:</p>
  <pre><code>Await.result(myFuture, Duration(30, TimeUnit.Seconds))
  </code></pre>
  <p>This works okay, but the future keeps running in the background, eating up threads in my thread pool.</p>
  <p>I then tried catching the TimeoutException and calling <code>myFuture.cancel(true)</code>, but it seems like <code>longRunningCall</code> doesn't respect the interruption and keeps running. This means my thread pool eventually just fills up with zombie threads.</p>
  <p>How can I run this task in a background thread and actually, forcibly, cancel it using Scala or Java?</p>
  <hr />
  <p>I'm aware of many other threads on the topic, but there is an assumption in the answers I see that I have control over the long-running task, e.g.</p>
  <p><a href="https://stackoverflow.com/questions/11158454/future-task-of-executorservice-not-truly-cancelling">Future task of ExecutorService not truly cancelling</a></p>
  <p><a href="https://stackoverflow.com/questions/16009837/how-to-cancel-future-in-scala">How to cancel Future in Scala?</a></p>
  <p><a href="https://stackoverflow.com/questions/23320407/how-to-cancel-java-8-completable-future">How to cancel Java 8 completable future?</a></p>
  <p>As such I do not see a question that is truly a duplicate.</p>
  <p>Is this just not possible?</p>