2009-05-16 3 views
0

첫 번째 스레드에서 두 번째 스레드를 생성하여 응용 프로그램을 호출합니다. 두 번째 스레드는 첫 번째 스레드에서 응용 프로그램을 호출 한 결과 읽기 파일로 생성됩니다. 응용 프로그램이 제대로 작동하지만 파일 읽기가 작동하지 않습니다.동기화 된 스레드

여기 내 코드입니다 :

/* 
* 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."); 
    } 
} 
+0

"파일을 읽지 않습니다."라고 말하면 작동하지 않는 코드를 게시하고 어떤 일이 일어나고 어떤 일이 발생하는지 예상 할 수 있습니다. –

답변

4
당신은 정말 당신이하려는 당신의 동기화 요구 사항이 무엇인지 무엇인지 분명하지 있기 때문에, 더 많은 코드를 게시 할 수 있습니다

.

t2.wait (3)은 무엇입니까? 왜 3 밀리 초를 기다리는거야? 어쩌면 당신은 3 초 (3000)를 의미 했었습니까? 여전히 위험하지만 귀하의 경우에는 효과가 있습니까?