yo diria que no es necesario eso de correrlos al mismo tiempo pero bueno. me extraña de que no sepas hacerlo como dices. este que yo hice seria lque se adapta perfecto a lo que dice Kinos
claro tu veras que tareas le pones
-------------------------------------------------------------------------------
-----------------------------------
:Performing the task : 0
-----------------------------------
Thread Control->Obtained:Task 1
->Restarting..Thread For Tasks
------------------------------------------------------------------------------------------------------------------
/**
*
* @author L-eyer
*/
class mainClass{
//---------------------------------------------------
public static void main
(final String[] args
){ threadForTasks tasks = new threadForTasks();
new ThreadControl(tasks);
tasks.start();
}
}
class threadForTasks
extends Thread{ private int task = 0 ;
private boolean active = true ;
private boolean received = false;
public int getTask() {return task;}
public void setTask(int index) {this.task = index;}
@Override public synchronized void run(){
while(active){
try {
}
System.
out.
println("-----------------------------------"); System.
out.
println(":Performing the task : "+task
); System.
out.
println("-----------------------------------"); task++;
received = true;
try {
wait();
}
}
}
public boolean isReceived() {
return received;
}
public void setReceived(boolean received) {
this.received = received;
}
public threadForTasks() {super("Thread For Tasks");
}
}
public class ThreadControl
extends Thread{ private threadForTasks thread;
private boolean activated = true ;
@Override public synchronized void run(){
while(activated){
try {if(thread.isReceived()){
System.
out.
println("\n"+getName
()+"->Obtained:Task "+thread.
getTask()+""); synchronized(thread){
System.
out.
println("->Restarting.."+thread.
getName()); thread.setReceived(false);
thread.notify();
}
}
e.printStackTrace();
}
}
}
public boolean isActivated() {
return activated;
}
public void setActivated(boolean activated) {
this.activated = activated;
}
public ThreadControl(threadForTasks threadNro1) {super("Thread Control");
this.thread = threadNro1;
start();
}
}
Saludos..