Skip to content

Proposal: Replacing ExecutorService to achieve more stable timing in the update loop #134

@ecmnet

Description

@ecmnet

The update loop is currently scheduled by an ExecutorService, which is known to be not very precise in its cyclic timing.

Therefore I would like to propose another solution for scheduling, which I currently use to avoid or at least reduce issues like polling errors or timeouts e.g. mentioned in this discussion.

Scheduling is implemented like this:

    long sleep_interval_ns;
    if (LOCKSTEP_ENABLED) {`
    	sleep_interval_ns = (long)(sleepInterval / speedFactor / checkFactor)*1000;
    } else {
    	sleep_interval_ns = sleepInterval*1000;
    }
    Thread loop = new Thread(() -> {
		long  wait;
		while(!shutdown) {
			wait = System.nanoTime();
			this.run();
			LockSupport.parkNanos(sleep_interval_ns - (System.nanoTime() - wait));    
		}
	});
    loop.setPriority(Thread.MAX_PRIORITY);
    loop.start();

On OSX this turned out to be much more stable although it is not solving the problem completely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions