I don't know if the following thing is possible. I would like a Runnable's run() method to contain the Runnable itself, i.e.
reconnects = 3;
Runnable executeAfter = () -> {
if ( --reconnects < 0 ) {
println("%nStop using port %d.", this.port);
//...
} else { // try to reconnect
println("%nReconnecting...");
cmdRun = new CmdRun(command, executeAfter);
(new Thread(cmdRun)).start();
//...
}
};
Is something like this even possible? If so, how? (CmdRun's constructor is CmdRun(String command, Runnable executeAfter))