File: BlockingRunnable.java

package info (click to toggle)
libglazedlists-java 1.8.0.dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,016 kB
  • sloc: java: 21,991; xml: 860; sh: 48; makefile: 5
file content (52 lines) | stat: -rw-r--r-- 1,483 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* Glazed Lists                                                 (c) 2003-2006 */
/* http://publicobject.com/glazedlists/                      publicobject.com,*/
/*                                                     O'Dell Engineering Ltd.*/
package ca.odell.glazedlists.impl.nio;

// NIO is used for CTP
/**
 * A Runnable that unblocks the calling thread when it finishes executing.
 *
 * <p>If this Runnable throws any {@link RuntimeException}s, they can be accessed
 * via this API. They will not be propagated up.
 */
class BlockingRunnable implements Runnable {

    /** the target runnable */
    private Runnable target;

    /** any exception thrown during invocation */
    private RuntimeException problem = null;

    /**
     * Creates a BlockingRunnable that runs the specified target while the calling
     * thread waits.
     */
    public BlockingRunnable(Runnable target) {
        this.target = target;
    }

    /**
     * Runs the specified task.
     */
    public void run() {
        // run the target runnable
        try {
            target.run();
        } catch(RuntimeException e) {
            this.problem = e;
        }

        // wake up the waiting thread
        synchronized(this) {
            notify();
        }
    }

    /**
     * Get any exception that was thrown during invocation.
     */
    public RuntimeException getInvocationTargetException() {
        return problem;
    }
}