diff --git a/wash/src/actor/ActorThread.java b/wash/src/actor/ActorThread.java index b7f992f..558aa21 100644 --- a/wash/src/actor/ActorThread.java +++ b/wash/src/actor/ActorThread.java @@ -4,7 +4,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.Optional; -public class ActorThread extends Thread { +public abstract class ActorThread extends Thread { private final LinkedBlockingQueue q = new LinkedBlockingQueue<>(); @@ -25,7 +25,21 @@ public class ActorThread extends Thread { return q.poll(timeout, TimeUnit.MILLISECONDS); } - protected Optional poll(long timeOut) throws InterruptedException { - return Optional.ofNullable(q.poll(timeOut, TimeUnit.MILLISECONDS)); + protected Optional poll(long timeOut) { + try { + return Optional.ofNullable(q.poll(timeOut, TimeUnit.MILLISECONDS)); + } catch (InterruptedException e) { + return Optional.empty(); + } catch (Exception e) { + return Optional.empty(); // Or exit the program + } + } + + protected void usleep(long time) { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + e.printStackTrace(); + } } } \ No newline at end of file