withTimeouts
public static boolean withTimeouts(java.lang.Runnable r,
long timeToGetInEDT,
long timeToRun)
throws java.lang.reflect.InvocationTargetException
Try to avoid deadlocks between the background task (sidekick parsing) and the AWT EDT
when the background task holds a lock the EDT is blocked waiting for and the background
task calls invokeAndWait() because it needs input from the user.
Deadlocks are not prevented, but the background task will back-out after some time.
Two timeouts may be specified:
- timeToGetInEDT is in case of existing blocked EDT; withTimeouts will return if r
has not began to run after timeToGetInEDT. When r eventually gets scheduled in the EDT
it will not be run if timeToGetInEDT has passed.
- timeToRun is in case r itself gets blocked waiting for some lock held by the background task.
withTimeouts will return anyway after timeToGetInEDT+timeToRun. r will not be interrupted.
withTimeouts will return early if interrupted, even if r is not done.
In this case, it will cancel running r (if it's not already running) and will return false.
if withTimeouts is called from the EDT it will run r synchronously
(timeout on timeToRun will not be respected)
- Parameters:
r
- task to run in the EDT
timeToGetInEDT
- presumably short time to wait for r to be scheduled in the EDT. 0 to wait forever, but it wouldn't make sense
timeToRun
- presumably longer time to wait for r to be run.
0 to wait forever, if you're sure the task will not block
and you except an answer from the user.
- Returns:
- if r was run successfully to completion
- Throws:
java.lang.reflect.InvocationTargetException
- if an exception is caught running r