Raggazzi chiedo un vostro aiuto su un concetto che riguarda i thread.
Semplifico il mio problema con uno equivalente che dia l'idea della mia difficoltà.
Da un main lancio 2 thead ed una classe supervisore (Monitor). I 2 thread : il primo NewThread1 conta ed aggiorna il monitor e rimane in attesa. Il secondo , NewThread, aggiorna il valore di una JProgressBar a partire dal valore letto dal Monitor e rimane in attesa. E' il paradigma produttore-consumatore sincronizzati.
Fino a quà tutto OK! . Riporto la classe principale che richiama i thread :

class ExtendThread {
public static void main(String args[]) {

Monitor m=new Monitor();
NewThread1 a=new NewThread1(m);
NewThread b=new NewThread(m,1);


System.out.println("\n vado in attesa sui primi 2");
try
{
a.t.join();
b.t.join();
} catch (InterruptedException e) {System.out.println("\n interruzione a e/o b");}

System.out.println("\n hanno finito i primi 2");

System.out.println("\n vado in attesa sul 3");
ThreadFrame tf=new ThreadFrame();
try{
tf.t.join();
} catch (InterruptedException e) {System.out.println("\n interruzione a e/o b");}

System.out.println("patch_s:"+tf.patch_s);
System.out.println("Exiting main thread.");
System.exit(0);


}
}


Il problema nasce quando riporto questo caso (esemplificato) a quello reale in cui i thread sopra descritti vengono istanziati da un ActionEvent. Infatti in tale circostanza non si osserva l'aggiornamento della JPROGRESSBAR.
In pratica la classe principale soprariportata diviene:

class ExtendThread {
public static void main(String args[]) {
Cruscotto cr=new Cruscotto();

}

dove Cruscotto() non è altro che un JPanel su cui è presente il bottone che avvia i Thread :

class Cruscotto extends JFrame implements ActionListener
{ JButton but;

public Cruscotto( )
{
but=new JButton("OK");
but.setFont(new Font("Comic Sans MS", 0, 9));
but.setBounds(new Rectangle(120, 5, 50, 20));
this.setTitle("Avvio");
this.setSize(new Dimension(200,60));
this.getContentPane().setSize(new Dimension(200,60));
but.addActionListener(this);
this.getContentPane().setLayout(null);
this.getContentPane().add(but,null);
//this.pack();
this.setVisible(true);

}
public void actionPerformed(ActionEvent me)
{
Monitor m=new Monitor();
NewThread1 a=new NewThread1(m);
NewThread b=new NewThread(m,1);
System.out.println("\n vado in attesa sui primi 2");
try
{
a.t.join();
b.t.join();
} catch (InterruptedException e) {System.out.println("\n interruzione a e/o b");}

System.out.println("\n hanno finito i primi 2");

System.out.println("\n vado in attesa sul 3");
ThreadFrame tf=new ThreadFrame();
try{
tf.t.join();
} catch (InterruptedException e) {System.out.println("\n interruzione a e/o b");}

System.out.println("patch_s:"+tf.patch_s);
System.out.println("Exiting main thread.");
System.exit(0);

}
}
}



Utilizzando Cruscotto la JFrame che contiene la JProgressBar compare ma non compare la JProgressBar (diversamente da prima dove funzionava tutto correttamente).

Per completezza riporto le altre classi:

Il Monitor:

class Monitor
{ private int valore_righe=0;
boolean valueSet=false;
Monitor() { }

synchronized void setRighe(int valore_righe)
{

if (valueSet)
try{
wait();
}catch(InterruptedException e){
}
this.valore_righe=valore_righe;
//System.out.println("\n valore settato:"+valore_righe);
valueSet=true;
notify();

}
synchronized int getRighe()
{

if (!valueSet)
try{
wait();
}catch(InterruptedException e){
}
valueSet=false;
notify();
//System.out.println("\n valore prelevato:"+valore_righe);
return this.valore_righe;

}

}

Il thread prduttore :
class NewThread1 extends Thread {
Thread t;
Monitor m;
NewThread1(Monitor m)
{
this.m=m;
t=new Thread(this, "NewThread1");
t.start();
}
public void run() {
try {
for(int i = 1; i <=100; i++)
{
//System.out.println("Child Thread: " + i);
m.setRighe(i);
Thread.sleep(10);
}
} catch (InterruptedException e) {
System.out.println("Child interrupted.");
}
//System.out.println("Exiting 1° thread.");
}
}

Il thread consumatore (con la JProgressBar) :

class NewThread extends JFrame implements Runnable //extends Thread
{
JProgressBar jp_int;
Monitor m_int;
int tot_righe;
Thread t;

NewThread(Monitor m,int numero_tot_righe)
{
this.setLocation(300, 300);
this.m_int=m;
this.tot_righe=numero_tot_righe;
this.setTitle("Caricamento");
this.setSize(new Dimension(200,60));
this.getContentPane().setSize(new Dimension(200,60));
this.setResizable(false);
jp_int=new JProgressBar(0,100);
this.jp_int.setStringPainted(true);
this.jp_int.setBounds(new Rectangle(10, 10, 200, 20));
this.getContentPane().add(jp_int,null);
this.setVisible(true);
this.addWindowListener(new MyWindowAdapter(this));
t=new Thread(this, "NewThread");
t.start();
}
public void run()
{
try{
int diff=tot_righe;
float r;
int rround;
while(diff<100)
{diff=m_int.getRighe();
this.jp_int.setValue(diff);
Thread.sleep(10);
}
} catch (InterruptedException e) {}
//System.out.println("Exiting 2° thread.");
}
}

Vi chiedo cortesemente di aiutarmi a capire perchè in questo secondo caso non si ha l'agiornamento della Bar.

Grazie anticipatamente,

Salvatore