-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadHandler.java
More file actions
52 lines (42 loc) · 1.43 KB
/
Copy pathThreadHandler.java
File metadata and controls
52 lines (42 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.nio.channels.Pipe;
import java.util.ArrayList;
import helpers.Coords;
import helpers.GDOutput;
import helpers.Pixels;
//manages java's threads
public class ThreadHandler {
private int processLimits;
private int completed;
private volatile int next;
private GDOutput[] outputs;
private volatile int currentRunnning;
public ThreadHandler(int number, int frames){
processLimits = number;
completed = 0;
next = 0;
outputs = new GDOutput[frames];
}
//create up to the limit # of threads to process gif
public GDOutput[] start(int iterations, int numDrones, double stepSize, int frameCount, Pixels image){
while(completed < frameCount){
if(currentRunnning < processLimits){
if(next == frameCount){
continue;
}
new ImageThread(next, image, this).setup(iterations, numDrones, stepSize).start();
System.out.println("Starting new thread: " + next);
next++;
currentRunnning++;
}
}
System.out.println("ended");
return outputs;
}
//remove thread and log output
public synchronized void remove(int id, GDOutput optimal){
outputs[id] = optimal;
completed++;
currentRunnning--;
System.out.println("Thread: " + id + " is done, total running: " + currentRunnning);
}
}