1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 03:00:30 +00:00

A couple of stability improvements to ComputerThread

- Be more generous in what errors we catch, handling some of the more
   "recoverable" ones.
 - Should a runner crash, attempt to restart it.
This commit is contained in:
SquidDev 2019-05-29 09:03:31 +01:00
parent 114f913bf8
commit 19aca001d7

View File

@ -133,7 +133,6 @@ public final class ComputerThread
synchronized( threadLock ) synchronized( threadLock )
{ {
running = true; running = true;
if( monitor == null || !monitor.isAlive() ) (monitor = monitorFactory.newThread( new Monitor() )).start();
if( runners == null ) if( runners == null )
{ {
@ -158,6 +157,8 @@ public final class ComputerThread
runnerFactory.newThread( runners[i] = new TaskRunner() ).start(); runnerFactory.newThread( runners[i] = new TaskRunner() ).start();
} }
} }
if( monitor == null || !monitor.isAlive() ) (monitor = monitorFactory.newThread( new Monitor() )).start();
} }
} }
@ -368,7 +369,16 @@ public final class ComputerThread
{ {
TaskRunner runner = currentRunners[i]; TaskRunner runner = currentRunners[i];
// If we've no runner, skip. // If we've no runner, skip.
if( runner == null ) continue; if( runner == null || runner.owner == null || !runner.owner.isAlive() )
{
if( !running ) continue;
// Mark the old runner as dead and start a new one.
ComputerCraft.log.warn( "Previous runner ({}) has crashed, restarting!",
runner != null && runner.owner != null ? runner.owner.getName() : runner );
if( runner != null ) runner.running = false;
runnerFactory.newThread( runners[i] = new TaskRunner() ).start();
}
// If the runner has no work, skip // If the runner has no work, skip
ComputerExecutor executor = runner.currentExecutor.get(); ComputerExecutor executor = runner.currentExecutor.get();
@ -492,7 +502,7 @@ public final class ComputerThread
{ {
executor.work(); executor.work();
} }
catch( Exception e ) catch( Exception | LinkageError | VirtualMachineError e )
{ {
ComputerCraft.log.error( "Error running task on computer #" + executor.getComputer().getID(), e ); ComputerCraft.log.error( "Error running task on computer #" + executor.getComputer().getID(), e );
} }