Timers/Thread with JTable.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   eyal_s
Posted On:   Friday, September 9, 2005 08:07 AM

Hello all, I create a table model that include objects(strings). Every "call" has a time to be desplay at the table , and after the time pass the cell at the table model set by default string like "XXX". I create a thread Queue that include threads object. every thread object get the time and the location at the table model. I think that i didn't set the threads very good, because if one thread is at sleep mode, all the rest of the threads are waiting too. public void createQueue(){ String[] call = new String[2]; for (int index=0; index < 100; index++) { call = random.getSingleCall(); if(!call[0].equals(call   More>>

Hello all,

I create a table model that include objects(strings).
Every "call" has a time to be desplay at the table , and after the time pass the cell at the
table model set by default string like "XXX".

I create a thread Queue that include threads object. every thread object get the
time and the location at the table model.

I think that i didn't set the threads very good, because if one thread is at sleep mode,
all the rest of the threads are waiting too.

			
public void createQueue(){

String[] call = new String[2];
for (int index=0; index < 100; index++) {
call = random.getSingleCall();
if(!call[0].equals(call[1])){
ThreadObject object = new ThreadObject(call[0],call[1]);
object.setWaitingStatus(random.randomInt(0,5));
ThreadQueue.addWork(object);
}
//if nor the same satations, or equals to X
}
//strat the threads
this.start();
}

/**
* This method run from the abstract class.
*/
public void run() {
try {
while (true) {
// Retrieve some work; block if the queue is empty
ThreadObject Object = ThreadQueue.getWork();
this.setNewMatrix(Object.getSourceCall(),Object.getDestinyCall(),Object);
Object.goToSleep();
Model.setValueAt("X->X",Object.getModelRow(),Object.getModelCol());
Model.update();
ThreadQueue.stopWork(Object);
simpleJTableAlgorithm.repaint();

if(ThreadQueue.getQueue().isEmpty()){
Object = null;
}
}
}catch (InterruptedException e) {
}
}



How can i fix this, or do you have better solution?
Thanks a lot,
Eyal    <<Less
About | Sitemap | Contact