mirror of
https://github.com/bspeice/itcs3146-project
synced 2024-11-09 09:38:23 -05:00
Fix up threading code, add methods for calling deallocation
This commit is contained in:
parent
f9a9069e3b
commit
f26a19a34a
6
Job.java
6
Job.java
@ -11,12 +11,12 @@
|
|||||||
public class Job {
|
public class Job {
|
||||||
private jobThread myThread; //Reference to the thread we control
|
private jobThread myThread; //Reference to the thread we control
|
||||||
private boolean myThreadPaused; //Used to keep track of the execution state of our thread
|
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
|
//Create a new job, and start it running
|
||||||
myThread = new jobThread(jobTime, jobID /*, parentAlgorithm*/);
|
myThread = new jobThread(jobTime, jobID, parentAlgorithmDeallocate);
|
||||||
myThread.start();
|
myThread.start();
|
||||||
|
myThreadPause = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pause(){
|
public void pause(){
|
||||||
|
@ -6,10 +6,11 @@ public class jobThread extends Thread {
|
|||||||
private long startTime;
|
private long startTime;
|
||||||
private int jobID;
|
private int jobID;
|
||||||
private boolean jobDone;
|
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.jobTime = jobTime;
|
||||||
|
this.parentAlgorithmDeallocate = parentAlgorithmDeallocate;
|
||||||
elapsedTime = 0;
|
elapsedTime = 0;
|
||||||
isPaused = false;
|
isPaused = false;
|
||||||
startTime = 0;
|
startTime = 0;
|
||||||
@ -69,7 +70,7 @@ public class jobThread extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//We're done, go ahead and notify our algorithm to clean us up
|
//We're done, go ahead and notify our algorithm to clean us up
|
||||||
/* parentAlgorithm.deallocate(jobID); */
|
parentAlgorithmDeallocate(jobID);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,24 @@
|
|||||||
class threadedAllocationGarbage
|
class threadedAllocationGarbage extends Thread
|
||||||
{
|
{
|
||||||
/* This class implements the garbage collecting functionality for the
|
/* This class implements the garbage collecting functionality for the
|
||||||
* threaded allocation algorithm.
|
* threaded allocation algorithm.
|
||||||
* It had to be put in a separate class since it implements a threading
|
* It had to be put in a separate class since it implements a threading
|
||||||
* interface */
|
* 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user