Problemas com wait, notify (Gerando IllegalMonitorStateException)

0 respostas
A

No código abaixo estou recebendo um IllegalMonitorStateException e não sei o motivo. Alguem poderia me ajudar???

//Na classe TestCashDispenserPanel

private JButton getBtnStartExchange() {

if (btnStartExchange == null) {

btnStartExchange = new JButton();

<a href="//btnStartExchange.setText">//btnStartExchange.setText</a>(“StartExchange”);

btnStartExchange.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

try {
Vector unit = new Vector();
                                            
                    synchronized (m_cTestDlg) {
                        StartExchangeDialog startExchangeDialog = 
                            new StartExchangeDialog(TestCashDispenserPanel.this, m_cLocal, unit);
                        try {
                        	System.out.println("Wait");
                        	this.wait(60000);
		System.out.println("End Wait");
	} catch (InterruptedException e1) {
		System.out.println("Problems with wait");
		e1.printStackTrace();
	}
                    	//Any Code
                        new InternalJxfsEventAdapter() { ...
                                            
                   }
        });
    }
    return btnStartExchange;
}
//Na classe StartExchangeDialog

if (btnOK == null) {

btnOK = new JButton();

btnOK.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent e) {

//m_cOwner = Instacia TestCashDispenserPanel

synchronized(m_cOwner){

if(chkCashUnit1.isSelected())

//Objeto recebido

units.add(new Integer(1));
if(chkCashUnit2.isSelected())
                    	v_Units.add(new Integer(2));
                    if(chkCashUnit3.isSelected())
                    	v_Units.add(new Integer(3));
                    if(chkCashUnit4.isSelected())
                    	v_Units.add(new Integer(4));
                    if(chkCashUnit5.isSelected())
                    	v_Units.add(new Integer(5));
                
                    System.out.println("notify");
                    m_cOwner.notifyAll();
                
                }
                StartExchangeDialog.this
                        .dispatchEvent(new WindowEvent(
                        		StartExchangeDialog.this,
                                WindowEvent.WINDOW_CLOSING));
                
            }
        });
    }
    return btnOK;
}

}

Criado 27 de junho de 2008
Respostas 0
Participantes 1