I think, instead of starting 7 threads, use one thread. 1. create a TaskWorker class
public class TaskWorker implements Runnable { private boolean quit = false; private Vector queue = new Vector(); public TaskWorker() { new Thread(this).start(); } private Task getNext() { Task task = null; if (!queue.isEmpty()) { task = (Task) queue.firstElement(); } return task; } public void run() { while (!quit) { Task task = getNext(); if (task != null) { task.doTask(); queue.removeElementAt(task); } else {
2. create an abstract task class
public abstract class Task { abstract void doTask(); }
3. Now create the task.
public class DownloadTask extends Task{ void doTask() {
4. and add this task to the workflow
TaskWorker taskWorker = new TaskWorker(); taskWorker.addTask(new DownloadTask());
Vivart
source share