mirror of
https://github.com/corda/corda.git
synced 2025-06-13 04:38:19 +00:00
implement Thread.interrupt()
This commit is contained in:
@ -7,14 +7,18 @@ public class Thread implements Runnable {
|
||||
private long peer;
|
||||
private final Runnable task;
|
||||
private Map<ThreadLocal, Object> locals;
|
||||
private Object sleepLock;
|
||||
private boolean interrupted;
|
||||
private Object sleepLock;
|
||||
|
||||
public Thread(Runnable task) {
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
public synchronized void start() {
|
||||
if (peer != 0) {
|
||||
throw new IllegalStateException("thread already started");
|
||||
}
|
||||
|
||||
Map<ThreadLocal, Object> map = currentThread().locals;
|
||||
if (map != null) {
|
||||
for (Map.Entry<ThreadLocal, Object> e: map.entrySet()) {
|
||||
@ -45,6 +49,26 @@ public class Thread implements Runnable {
|
||||
|
||||
public static native Thread currentThread();
|
||||
|
||||
private static native void interrupt(long peer);
|
||||
|
||||
public synchronized void interrupt() {
|
||||
if (peer != 0) {
|
||||
interrupt(peer);
|
||||
} else {
|
||||
interrupted = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean interrupted() {
|
||||
Thread t = currentThread();
|
||||
|
||||
synchronized (t) {
|
||||
boolean v = t.interrupted;
|
||||
t.interrupted = false;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
public static void sleep(long milliseconds) throws InterruptedException {
|
||||
Thread t = currentThread();
|
||||
if (t.sleepLock == null) {
|
||||
|
Reference in New Issue
Block a user