reswqa commented on code in PR #20229:
URL: https://github.com/apache/flink/pull/20229#discussion_r917878601
##########
flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/core/testutils/CheckedThread.java:
##########
@@ -18,26 +18,42 @@
package org.apache.flink.core.testutils;
+import java.util.concurrent.TimeoutException;
+
/**
* A thread that additionally catches exceptions and offers a joining method
that re-throws the
* exceptions.
*
- * <p>Rather than overriding {@link Thread#run()} (or supplying a {@link
Runnable}), one needs to
- * extends this class and implement the {@link #go()} method. That method may
throw exceptions.
+ * <p>This class needs to supply a {@link RunnableWithException} that may
throw exceptions or
+ * override {@link #go()} method.
+ *
+ * <p>you can use it as the same way of using threads like: {@code new
Thread(Runnable runnable)} or
+ * {@Code new Thread()} and then override {@link Thread#run()} method. Just
change it to {@code new
+ * CheckedThread(RunnableWithException runnableWithException)} or {@Code new
CheckedThread()} and
+ * then override {@link CheckedThread#go()} method.
*
- * <p>Exception from the {@link #go()} method are caught and re-thrown when
joining this thread via
- * the {@link #sync()} method.
+ * <p>Exception from the {@link #runnable} or the override {@link #go()} are
caught and re-thrown
+ * when joining this thread via the {@link #sync()} method.
*/
-public abstract class CheckedThread extends Thread {
+public class CheckedThread extends Thread {
Review Comment:
I think when using `CheckedThread` you should keep the habit of using
`Thread`: pass in a runnable or override the go method.
Another reason is that I found that many test classes such as:
`org.apache.flink.core.fs.LimitedConnectionsFileSystemTest.BlockingWriterThread`
will be ugly if they do not support overriding the go method: I thought about
introducing a class `BlockingWriterRunnable` extends `RunnableWithExcpetion`,
and then let the field of BlockingWriterThread and the logic of the go method
are transferred to BlockingWriterRunnable, and then replaced it with `new
CheckedThrad(new BlockingWriterRunnable(xxx) )` where `BlockingWriterThread` is
used. This is very inconvenient to use, because the test class will call the
`sync` on `CheckedThread`, and also call the `wakeup` method on
`BlockingWriterRunnable`, but in the original implementation, these methods
are all on `BlockingWriterThread`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]