From 3ee353710fc7550243b34d43ccd00164e3786b15 Mon Sep 17 00:00:00 2001 From: Yiteng Guo Date: Tue, 3 Dec 2019 04:48:01 -0500 Subject: [PATCH] add an interrupt test case --- tests/isolated/InterruptTest.java | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/isolated/InterruptTest.java diff --git a/tests/isolated/InterruptTest.java b/tests/isolated/InterruptTest.java new file mode 100644 index 00000000..aff2d4fe --- /dev/null +++ b/tests/isolated/InterruptTest.java @@ -0,0 +1,37 @@ +public class InterruptTest { + public static void main(String args[]) { + Thread current = Thread.currentThread(); + System.out.println(current.isInterrupted()); + current.interrupt(); + System.out.println(current.isInterrupted()); + System.out.println(current.isInterrupted()); + System.out.println(Thread.interrupted()); + System.out.println(current.isInterrupted()); + current.interrupt(); + synchronized (current) { + try { + current.wait(1); + System.out.println("no"); + } catch (InterruptedException e) { + System.out.println(e.getClass()); + } + } + synchronized (current) { + try { + current.wait(1); + System.out.println("yes"); + } catch (InterruptedException e) { + System.out.println(e.getClass()); + } + } + current.interrupt(); + synchronized (current) { + try { + current.join(); + System.out.println("yes"); + } catch (InterruptedException e) { + System.out.println(e.getClass()); + } + } + } +}