From 83497b1b9eb92c3c3eda2941f7658fd41e678b4e Mon Sep 17 00:00:00 2001 From: Steve Hannah Date: Tue, 2 Jun 2015 10:38:33 -0700 Subject: [PATCH] Implemented Thread.join() --- .../org/teavm/classlib/java/lang/TThread.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java index c4de1d645..707cc0f97 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java @@ -36,7 +36,9 @@ public class TThread extends TObject implements TRunnable { private int priority = 0; private long timeSliceStart; private int yieldCount; - + private final Object finishedLock = new Object(); + + private TString name; TRunnable target; @@ -90,6 +92,9 @@ public class TThread extends TObject implements TRunnable { if (target != null) { target.run(); } + synchronized(finishedLock) { + finishedLock.notifyAll(); + } } public static TThread currentThread() { @@ -99,6 +104,23 @@ public class TThread extends TObject implements TRunnable { public TString getName() { return name; } + + public final void join(long millis, int nanos) throws InterruptedException { + if (currentThread() == this) { + return; + } + synchronized(finishedLock) { + finishedLock.wait(millis, nanos); + } + } + + public final void join(long millis) throws InterruptedException { + join(millis, 0); + } + + public final void join() throws InterruptedException { + join(0); + } public static void yield() { TThread currentThread = currentThread();