views:

48

answers:

1

Hi I create two thread first thread to call application and second thread for read file that result from calling aplication on the first thread. Call application work fine but read the file doesnt work. can you help me plz? here is my code

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reciverwindow;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * 
 */
public class NewClass1 implements Runnable {

    public static void main(String[] args) {

        CallMatlab c = new CallMatlab();
        CUI m = new CUI();
        Thread t1 = new Thread(c);
         t1.start();
        Thread t2 = new Thread(m);

        t2.start();
       /* try {
            t2.sleep(3);
        } catch (InterruptedException ex) {
            Logger.getLogger(NewClass1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }*/


   synchronized (t2) {
            try {
                t2.wait(3);
                  t2.notifyAll();
            } catch (InterruptedException ex) {
                Logger.getLogger(NewClass1.class.getName()).log(Level.SEVERE, null, ex);
            }
            }


    }

    public void run() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
+3  A: 

You may want to post more code, because it's really not clear what you're trying to do and what your synchronization requirements are.

What's peculiar is your t2.wait(3). Why are you waiting three milliseconds? Maybe you meant three seconds (3000), which is still risky but might work in your case ?

Uri