Fix up threading code, add methods for calling deallocation

This commit is contained in:
Bradlee Speice 2012-11-06 13:33:20 -05:00
parent f9a9069e3b
commit f26a19a34a
3 changed files with 24 additions and 7 deletions

View File

@ -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(){

View File

@ -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;
}

View File

@ -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
}
}