코드를 동기화하기 위해 조인을 사용하려고합니다. 조인을 호출하면 부모와 자식 스레드 모두에서 예외가 발생합니다. 스레드 "thread3"의 예외가 스레드 실행시 예외입니다.자바를 호출 할 때 자식 및 부모 스레드에서 예외가 발생합니다
스레드는 Ruinable 클래스에서 실행되며 클래스가 생성 될 때 공용 멤버에 스레드를 저장합니다. 메인 스레드는이 공용 멤버에서 join 메서드를 호출합니다.
코드 메인 스레드
는 "메인 스레드는"당신은 스레드를 생성하지만, 그것을 시작하지 않는 전화 코드 조각에서System.out.println(Thread.currentThread()+": waiting for 2 players");
do {
r=GetClient();
switch(r)
{
case 0: return; // exitvon a very bad error
}
} while(r==2);// loop if it was a timeout
cMyConnection thread = new cMyConnection("thread3", connection, mPlayerList, mPlayersMessages);
try {
thread.MyThread.join(); // call join
} catch (InterruptedException e) {
e.printStackTrace();
}
클래스
public class Cconnection implements Runnable {
Thread runner;
ReentrantReadWriteLock readWriteLock;
Lock read;
Lock write;
boolean StopFlag;
String header;
Socket connection;
ServerSocket server;
StringBuffer request;
OutputStream out;
InputStream in;
String ClientMessage;
public cUsers mPlayerList;
public cMessages mPlayersMessages;
public Thread MyThread;
public Cconnection(String threadName, Socket connection_in , cUsers PlayerList, cMessages PlayerMessages) {
connection=connection_in;
mPlayerList=PlayerList;
mPlayersMessages=PlayerMessages;
MyThread = new Thread(this, threadName); // (1) Create a new thread.
MyThread.start(); // (2) Start the thread.
}
게시물을 수정하십시오 ... – L7ColWinters
stacktrace를 포함하십시오. – mre