Skip to content
Snippets Groups Projects
Commit 7a48afd0 authored by Miska Sulander's avatar Miska Sulander
Browse files

assignment 1 ready

parent 8d2971c6
No related branches found
No related tags found
No related merge requests found
......@@ -17,12 +17,11 @@ public class MyThread extends Thread {
}
public void run() {
mediator.registerThread(this.hashCode(), "Thread");
mediator.setRunStatus("Created", this.hashCode());
// Set thread status to running
mediator.setRunStatus("Running", this.hashCode());
int count = control.getBlockSize();
// Run works from work list while works are present in work list
while (!((workList = mediator.getWorkSlice(control.getBlockSize())).isEmpty())) {
workList = mediator.getWorkSlice(count); //get count amount of works from work queue
for( Work item : workList) {
mediator.setWorkStatus("Calculating", item);
item.work();
......@@ -30,6 +29,14 @@ public class MyThread extends Thread {
mediator.increaseCalculated(this.hashCode());
}
}
// Set thread status to ended when worklist is empty
mediator.setRunStatus("Ended", this.hashCode());
}
// Method for registering threads
public void register() {
mediator.registerThread(this.hashCode(), "Thread");
mediator.setRunStatus("Created", this.hashCode());
}
}
......@@ -14,10 +14,21 @@ public class Task1UsingThreadDistributor implements Distributor {
}
public void execute() {
// Create list for storing threads
Thread threads[] = new Thread[control.getThreadCount()];
for (int i = 0 ; i < control.getThreadCount() ; ++i) { //get number of threads from UI and create threads
/* Get number of threads from UI and create threads,
* then register threads.
*/
for (int i = 0 ; i < control.getThreadCount() ; ++i) {
threads[i] = new MyThread(mediator, control);
threads[i].start();
((MyThread) threads[i]).register();
}
// Start all threads.
for (Thread thread : threads) {
thread.start();
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment