equal
deleted
inserted
replaced
476 return comThread; |
476 return comThread; |
477 } |
477 } |
478 |
478 |
479 public <T> T invoke(Callable<T> task) { |
479 public <T> T invoke(Callable<T> task) { |
480 try { |
480 try { |
481 T result; |
|
482 if (Thread.currentThread() == comThread) { |
481 if (Thread.currentThread() == comThread) { |
483 // if it's already called from the COM |
482 // if it's already called from the COM |
484 // thread, we don't need to delegate the task |
483 // thread, we don't need to delegate the task |
485 result = task.call(); |
484 return task.call(); |
486 } else { |
485 } else { |
487 Future<T> future = submit(task); |
486 while (true) { |
488 try { |
487 Future<T> future = submit(task); |
489 result = future.get(); |
488 |
490 } catch (InterruptedException e) { |
489 try { |
491 result = null; |
490 return future.get(); |
492 future.cancel(true); |
491 } catch (InterruptedException e) { |
493 } |
492 // Repeat the attempt |
494 } |
493 future.cancel(true); |
495 return result; |
494 } |
|
495 } |
|
496 } |
496 } catch (Exception e) { |
497 } catch (Exception e) { |
497 Throwable cause = (e instanceof ExecutionException) ? e.getCause() : e; |
498 Throwable cause = (e instanceof ExecutionException) ? e.getCause() : e; |
498 if (cause instanceof RuntimeException) { |
499 if (cause instanceof RuntimeException) { |
499 throw (RuntimeException) cause; |
500 throw (RuntimeException) cause; |
500 } |
501 } |