diff --git a/Job.java b/Job.java index 966e9dd..beae1d2 100644 --- a/Job.java +++ b/Job.java @@ -11,12 +11,12 @@ public class Job { private jobThread myThread; //Reference to the thread we control private boolean myThreadPaused; //Used to keep track of the execution state of our thread - //private BaseAlgorithm parentAlgorithm; //Used for knowing who to tell that we're done. - public Job(int jobTime, int jobID/*, BaseAlgorithm parentAlgorithm */){ + public Job(int jobTime, int jobID, Method parentAlgorithmDeallocate ){ //Create a new job, and start it running - myThread = new jobThread(jobTime, jobID /*, parentAlgorithm*/); + myThread = new jobThread(jobTime, jobID, parentAlgorithmDeallocate); myThread.start(); + myThreadPause = false; } public void pause(){ diff --git a/jobThread.java b/jobThread.java index a04edc2..26a0462 100644 --- a/jobThread.java +++ b/jobThread.java @@ -6,10 +6,11 @@ public class jobThread extends Thread { private long startTime; private int jobID; private boolean jobDone; - /* private BaseAlgorithm parentAlgorithm *///Our parent to notify when we're done. + private Method parentAlgorithmDeallocate; //Our parent to notify when we're done. - public jobThread(long jobTime, int jobID /*, BaseAlgorithm parentAlgorithm*/){ + public jobThread(long jobTime, int jobID, Method parentAlgorithmDeallocate){ this.jobTime = jobTime; + this.parentAlgorithmDeallocate = parentAlgorithmDeallocate; elapsedTime = 0; isPaused = false; startTime = 0; @@ -69,7 +70,7 @@ public class jobThread extends Thread { } //We're done, go ahead and notify our algorithm to clean us up - /* parentAlgorithm.deallocate(jobID); */ + parentAlgorithmDeallocate(jobID); } catch (Exception e) { return; } diff --git a/threadedAllocationGarbage.java b/threadedAllocationGarbage.java index 1bc0c4c..69dc4de 100644 --- a/threadedAllocationGarbage.java +++ b/threadedAllocationGarbage.java @@ -1,8 +1,24 @@ -class threadedAllocationGarbage +class threadedAllocationGarbage extends Thread { /* This class implements the garbage collecting functionality for the * threaded allocation algorithm. * It had to be put in a separate class since it implements a threading * interface */ + int[] memoryBlock; + int sleepTime; + + threadedAllocationGarbage( int[] memoryBlock, int sleepTime ){ + /* Set up a reference to the algorithm's memory location */ + this.memoryBlock = memoryBlock; + + /* Set up the time quantum */ + this.sleepTime = sleepTime; + } + + public void run() { + /* Code to run in the background */ + + //Sleep for sleepTime, then scan for memory to compact + } }