Запись информации о текущих задачах в лог.
This commit is contained in:
@@ -27,17 +27,31 @@ public abstract class ThreadsPlanner {
|
||||
public ThreadsPlanner(int wait_ms_in) {
|
||||
wait_ms = wait_ms_in;
|
||||
}
|
||||
public void setMaxKernels(int maxKernels_in){
|
||||
public void setMaxKernels(int maxKernels_in) {
|
||||
maxKernels = maxKernels_in;
|
||||
kernels = maxKernels;
|
||||
}
|
||||
public String printThread(Integer id) {
|
||||
return "thread id = "+id;
|
||||
}
|
||||
public String getThreadsSummary() {
|
||||
Vector<String> lines = new Vector<>();
|
||||
lines.add("Planner summary:");
|
||||
lines.add("Waiting: " + waitingThreads.size());
|
||||
lines.add("Running: " + activeThreads.size());
|
||||
for (Integer id : activeThreads) {
|
||||
lines.add(printThread(id));
|
||||
}
|
||||
lines.add("");
|
||||
return String.join("\n", lines);
|
||||
}
|
||||
//--
|
||||
public void Start() {
|
||||
Global.Log.Print("Planner started");
|
||||
try {
|
||||
//--
|
||||
while (!waitingThreads.isEmpty() || !activeThreads.isEmpty()) {
|
||||
Global.Log.Print("Waiting: " + waitingThreads.size() + "; Running: " + activeThreads.size() + ".");
|
||||
Global.Log.Print(getThreadsSummary());
|
||||
checkActiveThreads();
|
||||
tryStartThreads();
|
||||
Thread.sleep(wait_ms);
|
||||
@@ -45,8 +59,7 @@ public abstract class ThreadsPlanner {
|
||||
//--
|
||||
} catch (Exception exception) {
|
||||
Global.Log.PrintException(exception);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
Global.Log.Print("Planner finished");
|
||||
finalize();
|
||||
}
|
||||
@@ -82,8 +95,7 @@ public abstract class ThreadsPlanner {
|
||||
}
|
||||
protected void finalize() {
|
||||
}
|
||||
protected void addThread(Runnable runnable) {
|
||||
Thread thread = new Thread(runnable);
|
||||
protected void addThread(Thread thread) {
|
||||
threads.put(threadMaxId, thread);
|
||||
waitingThreads.add(threadMaxId);
|
||||
threadMaxId++;
|
||||
|
||||
Reference in New Issue
Block a user