From c160af437ee32c672f10d26c5171ca70870842cb Mon Sep 17 00:00:00 2001 From: meawoppl Date: Sat, 11 May 2019 08:54:37 -0700 Subject: [PATCH 1/4] Move to interrupt --- src/main/java/me/tongfei/progressbar/ProgressBar.java | 2 +- src/main/java/me/tongfei/progressbar/ProgressThread.java | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/tongfei/progressbar/ProgressBar.java b/src/main/java/me/tongfei/progressbar/ProgressBar.java index 385c58c..019e723 100644 --- a/src/main/java/me/tongfei/progressbar/ProgressBar.java +++ b/src/main/java/me/tongfei/progressbar/ProgressBar.java @@ -165,7 +165,7 @@ public ProgressBar stop() { */ @Override public void close() { - target.kill(); + thread.interrupt(); try { thread.join(); target.consoleStream.print("\n"); diff --git a/src/main/java/me/tongfei/progressbar/ProgressThread.java b/src/main/java/me/tongfei/progressbar/ProgressThread.java index 36f7114..8796c1b 100644 --- a/src/main/java/me/tongfei/progressbar/ProgressThread.java +++ b/src/main/java/me/tongfei/progressbar/ProgressThread.java @@ -44,7 +44,6 @@ class ProgressThread implements Runnable { this.style = style; this.updateInterval = updateInterval; this.consoleStream = consoleStream; - this.killed = false; this.unitName = unitName; this.unitSize = unitSize; this.isSpeedShown = isSpeedShown; @@ -150,13 +149,9 @@ void refresh() { consoleStream.print(line); } - void kill() { - killed = true; - } - public void run() { try { - while (!killed) { + while (!Thread.interrupted()) { refresh(); Thread.sleep(updateInterval); } From 1b72766ef5d0c272efa02d3da5943278e9af587b Mon Sep 17 00:00:00 2001 From: meawoppl Date: Sat, 11 May 2019 09:14:34 -0700 Subject: [PATCH 2/4] Bump version number --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cf29424..b37dc5a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.tongfei progressbar - 0.7.3 + 0.7.4 progressbar A console-based progress bar for JVM http://github.com/ctongfei/progressbar From e636c62019c5651d96a4d79b70e0f8d416fdd2c1 Mon Sep 17 00:00:00 2001 From: meawoppl Date: Fri, 17 May 2019 08:40:50 -0700 Subject: [PATCH 3/4] Revert version number change --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b37dc5a..cf29424 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.tongfei progressbar - 0.7.4 + 0.7.3 progressbar A console-based progress bar for JVM http://github.com/ctongfei/progressbar From c1caa6034ec5c0596d4ab21f87e07964fff6b1f7 Mon Sep 17 00:00:00 2001 From: meawoppl Date: Fri, 17 May 2019 14:10:06 -0700 Subject: [PATCH 4/4] Add a test --- .../me/tongfei/progressbar/Issue50Test.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/java/me/tongfei/progressbar/Issue50Test.java diff --git a/src/test/java/me/tongfei/progressbar/Issue50Test.java b/src/test/java/me/tongfei/progressbar/Issue50Test.java new file mode 100644 index 0000000..7335095 --- /dev/null +++ b/src/test/java/me/tongfei/progressbar/Issue50Test.java @@ -0,0 +1,19 @@ +package me.tongfei.progressbar; + +import org.junit.Test; + +public class Issue50Test { + @Test + public void testCloseSpeed() throws Exception { + int tenSecondsInMS = 10 * 1000; + long startTime = System.currentTimeMillis(); + + try(ProgressBar pb = new ProgressBar("Foo", 100, tenSecondsInMS)){ + Thread.sleep(5); + } + + long endTime = System.currentTimeMillis(); + + assert((endTime - startTime) < tenSecondsInMS); + } +}