job worker thread
This commit is contained in:
@@ -68,7 +68,7 @@ public abstract class AbstractJob implements Runnable {
|
||||
this.markStopRunTime();
|
||||
}
|
||||
|
||||
protected abstract void doJob();
|
||||
public abstract void doJob();
|
||||
|
||||
public void executeJob(String threadName) {
|
||||
this.workerID.set(threadName);
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class AbstractScheduleJob extends AbstractJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected abstract void doJob();
|
||||
public abstract void doJob();
|
||||
|
||||
public void cancelJob() {
|
||||
JobScheduler.getInstance().cancelScheduledJob(this);
|
||||
|
||||
@@ -16,7 +16,7 @@ public class JobContainer implements Comparable<JobContainer> {
|
||||
final long timeOfExecution;
|
||||
final boolean noTimer;
|
||||
|
||||
JobContainer(AbstractJob job, long timeOfExecution) {
|
||||
public JobContainer(AbstractJob job, long timeOfExecution) {
|
||||
if (job == null) {
|
||||
throw new IllegalArgumentException("No 'null' jobs allowed.");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package engine.job;
|
||||
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class JobThread implements Runnable {
|
||||
private final AbstractJob currentJob;
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
public JobThread(AbstractJob job){
|
||||
this.currentJob = job;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (this.currentJob != null) {
|
||||
if (lock.tryLock(5, TimeUnit.SECONDS)) { // Timeout to prevent deadlock
|
||||
try {
|
||||
this.currentJob.doJob();
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
} else {
|
||||
Logger.warn("JobThread could not acquire lock in time, skipping job.");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void startJobThread(AbstractJob job){
|
||||
JobThread jobThread = new JobThread(job);
|
||||
Thread thread = new Thread(jobThread);
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
@@ -58,8 +58,11 @@ public class JobWorker extends ControlledRunnable {
|
||||
} else {
|
||||
|
||||
// execute the new job..
|
||||
this.currentJob.executeJob(this.getThreadName());
|
||||
this.currentJob = null;
|
||||
//this.currentJob.executeJob(this.getThreadName());
|
||||
if(this.currentJob != null) {
|
||||
JobThread.startJobThread(this.currentJob);
|
||||
this.currentJob = null;
|
||||
}
|
||||
}
|
||||
Thread.yield();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract class AbstractEffectJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected abstract void doJob();
|
||||
public abstract void doJob();
|
||||
|
||||
@Override
|
||||
protected abstract void _cancelJob();
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ActivateBaneJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
City city;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class AttackJob extends AbstractJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
CombatManager.doCombat(this.source, slot);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class BaneDefaultTimeJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
//bane already set.
|
||||
if (this.bane.getLiveDate() != null) {
|
||||
|
||||
@@ -97,7 +97,7 @@ public class BasicScheduledJob extends AbstractJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (execution == null) {
|
||||
Logger.error("BasicScheduledJob executed with nothing to execute.");
|
||||
return;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class BonusCalcJob extends AbstractJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (this.ac != null) {
|
||||
this.ac.applyBonuses();
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class CSessionCleanupJob extends AbstractJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
SessionManager.cSessionCleanup(secKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ChangeAltitudeJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (this.ac != null)
|
||||
MovementManager.finishChangeAltitude(ac, targetAlt);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class ChantJob extends AbstractEffectJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (this.aej == null || this.source == null || this.target == null || this.action == null || this.power == null || this.source == null || this.eb == null)
|
||||
return;
|
||||
PlayerBonuses bonuses = null;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class CloseGateJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
if (building == null) {
|
||||
Logger.error("Rungate building was null");
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DamageOverTimeJob extends AbstractEffectJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (this.target.getObjectType().equals(GameObjectType.Building)
|
||||
&& ((Building) this.target).isVulnerable() == false) {
|
||||
_cancelJob();
|
||||
|
||||
@@ -28,7 +28,7 @@ public class DatabaseUpdateJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (this.ago == null)
|
||||
return;
|
||||
ago.removeDatabaseJob(this.type, false);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class DebugTimerJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (this.pc == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DeferredPowerJob extends AbstractEffectJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
//Power ended with no attack, cancel weapon power boost
|
||||
if (this.source != null && this.source instanceof PlayerCharacter) {
|
||||
((PlayerCharacter) this.source).setWeaponPower(null);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class DisconnectJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (this.origin != null) {
|
||||
this.origin.disconnect();
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class DoorCloseJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
int doorNumber;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class EndFearJob extends AbstractEffectJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
//cancel fear for mob.
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class FinishCooldownTimeJob extends AbstractJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
PowersManager.finishCooldownTime(this.msg, this.pc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class FinishEffectTimeJob extends AbstractEffectJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
PowersManager.finishEffectTime(this.source, this.target, this.action, this.trains);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class FinishRecycleTimeJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
PowersManager.finishRecycleTime(this.msg, this.pc, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class FinishSpireEffectJob extends AbstractEffectJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
PlayerCharacter pc = (PlayerCharacter) target;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class FinishSummonsJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
if (this.target == null)
|
||||
return;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class LoadEffectsJob extends AbstractJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (this.originToSend == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class LogoutCharacterJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
server.logoutCharacter(this.pc);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class NoTimeJob extends AbstractEffectJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,7 +40,7 @@ public class PersistentAoeJob extends AbstractEffectJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
if (this.aej == null || this.source == null || this.action == null || this.power == null || this.source == null || this.eb == null)
|
||||
return;
|
||||
|
||||
@@ -45,7 +45,7 @@ public class RefreshGroupJob extends AbstractJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
if (this.pc == null || this.origin == null || grp == null) {
|
||||
return;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class RemoveCorpseJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
if (this.corpse != null)
|
||||
Corpse.removeCorpse(corpse, true);
|
||||
|
||||
@@ -25,7 +25,7 @@ public class SiegeSpireWithdrawlJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
if (spire == null)
|
||||
return;
|
||||
|
||||
@@ -30,7 +30,7 @@ public class StuckJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
Vector3fImmutable stuckLoc;
|
||||
Building building = null;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SummonSendJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
if (this.source == null)
|
||||
return;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class TeleportJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
if (this.pc == null || this.npc == null || this.origin == null)
|
||||
return;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class TrackJob extends AbstractEffectJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
if (this.tpa == null || this.target == null || this.action == null || this.source == null || this.eb == null || !(this.source instanceof PlayerCharacter))
|
||||
return;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class TransferStatOTJob extends AbstractEffectJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (this.dot == null || this.target == null || this.action == null || this.source == null || this.eb == null || this.action == null || this.power == null)
|
||||
return;
|
||||
if (!this.target.isAlive()) {
|
||||
|
||||
@@ -26,7 +26,7 @@ public class UpdateGroupJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
if (this.group == null)
|
||||
return;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class UpgradeBuildingJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
|
||||
// Must have a building to rank!
|
||||
|
||||
@@ -27,7 +27,7 @@ public class UpgradeNPCJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
int newRank;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class UseItemJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
PowersManager.finishApplyPower(ac, target, Vector3fImmutable.ZERO, pb, trains, liveCounter);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class UseMobPowerJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
PowersManager.finishUseMobPower(this.msg, this.caster, casterLiveCounter, targetLiveCounter);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class UsePowerJob extends AbstractScheduleJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
PowersManager.finishUsePower(this.msg, this.pc, casterLiveCounter, targetLiveCounter);
|
||||
}
|
||||
|
||||
|
||||
@@ -665,7 +665,7 @@ public abstract class AbstractConnectionManager extends ControlledRunnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (runStatus) {
|
||||
this.ac.connMan.receive(sk);
|
||||
this.ac.execTask.compareAndSet(true, false);
|
||||
@@ -694,7 +694,7 @@ public abstract class AbstractConnectionManager extends ControlledRunnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
if (runStatus) {
|
||||
this.ac.connMan.sendFinish(sk);
|
||||
this.ac.execTask.compareAndSet(true, false);
|
||||
|
||||
@@ -23,7 +23,7 @@ public class CheckNetMsgFactoryJob extends AbstractJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
NetMsgFactory factory = conn.getFactory();
|
||||
|
||||
// Make any/all msg possible
|
||||
|
||||
@@ -26,7 +26,7 @@ public class ConnectionMonitorJob extends AbstractJob {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doJob() {
|
||||
public void doJob() {
|
||||
|
||||
if (this.cnt >= 5) {
|
||||
this.connMan.auditSocketChannelToConnectionMap();
|
||||
|
||||
Reference in New Issue
Block a user