Does Java Start / Stop interface already exist?

Is there an interface with this contract

start(); stop(); 

Already exists?

I got the impression that here you can rewrite something classic ...

+4
source share
5 answers

I don’t think so, but I would say, even if this happens, it would be much more convenient to write your own just in case in the future, when you need to correct it and add pause(); or the like.

+3
source

No, at least without adding additional packages, but it is quite simple to create it:

 public interface StartAndStoppable { //I am *terrible* at coming up with names :P public void start(); public void stop(); } 

This is good because you can also add new methods if needed later.

+1
source

I have never heard of such an interface among the standard Java classes.

But something remotely resembling what you are looking for might be the java.util.concurrent.FutureTask class using the run() and cancel(boolean) methods.

0
source

If pure naming is not as critical as requiring standard Java, then:

  • java.lang.Runnable.run () as start ()
  • java.io.Closeable.close () as stop ()

"io" may be confusing, but it sounds fine to start / stop the embedded web server. The reason that you do not invent your own interface may be the complete decoupling of the modules without introducing a third module (containing the interface that just came up).

-1
source

Source: https://habr.com/ru/post/1481754/


All Articles