Implemented toggling of multithreading
This commit is contained in:
40
kryonet/src/io/anuke/kryonet/DefaultThreadImpl.java
Normal file
40
kryonet/src/io/anuke/kryonet/DefaultThreadImpl.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package io.anuke.kryonet;
|
||||
|
||||
import io.anuke.mindustry.core.ThreadHandler.ThreadProvider;
|
||||
import io.anuke.ucore.util.Log;
|
||||
|
||||
public class DefaultThreadImpl implements ThreadProvider {
|
||||
private Thread thread;
|
||||
|
||||
@Override
|
||||
public boolean isOnThread() {
|
||||
return Thread.currentThread() == thread;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sleep(long ms) throws InterruptedException{
|
||||
Thread.sleep(ms);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Runnable run) {
|
||||
if(thread != null){
|
||||
thread.interrupt();
|
||||
thread = null;
|
||||
}
|
||||
|
||||
thread = new Thread(run);
|
||||
thread.setDaemon(true);
|
||||
thread.setName("Update Thread");
|
||||
thread.start();
|
||||
Log.info("Starting logic thread.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if(thread != null){
|
||||
thread.interrupt();
|
||||
thread = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user