불루투스를 통해 인풋스트림을 열어 read하는 스레드입니다. <div>대략 아래와 같이 구성되어 있습니다</div> <div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px;"><div><font size="3">try{</font></div> <div><font size="3"><span style="white-space:pre;"> </span>Inputstream Input = 블루투스소켓에서 getInputstream();</font></div> <div><font size="3"><span style="white-space:pre;"> </span>...</font></div> <div><font size="3"><span style="white-space:pre;"> </span>while (!Thread.currentThread().isInterrupted()) {</font></div> <div><font size="3"><span style="white-space:pre;"> </span>if(Input.available() > 0){</font></div> <div><span style="font-size:medium;white-space:pre;"> </span><span style="font-size:medium;">cycle...</span></div> <div><font size="3"><span style="white-space:pre;"> </span>}else{</font></div> <div><font size="3"><span style="white-space:pre;"> </span>Thread.sleep(1000);</font></div> <div><font size="3"><span style="white-space:pre;"> </span>}</font></div> <div><font size="3"><span style="white-space:pre;"> </span>}</font></div> <div><font size="3">}catch (IOException ex){</font></div> <div><font size="3">}catch (InterruptedException e) {</font></div> <div><font size="3">}finally{</font></div> <div><font size="3"><span style="white-space:pre;"> </span>Input.close();</font></div> <div><font size="3">}</font></div></blockquote> <div><br></div> <div>해당 쓰레드의 인터럽트는 제가 블루투스 통신을 끊을때 다음과 같이 호출합니다.</div> <div><br></div> <div><div>if (쓰레드변수 != null) {</div> <div><span style="white-space:pre;"> </span>if (쓰레드변수.isAlive()) {</div> <div><span style="white-space:pre;"> </span>쓰레드변수.interrupt();</div> <div><span style="white-space:pre;"> </span>쓰레드변수 = null;</div> <div><span style="white-space:pre;"> </span>}</div> <div>}</div></div> <div>블루투스 소켓 close();</div> <div><br></div> <div>블루투스 통신을 다시 붙일때도 위와 같은 if문으로 확인하고요.</div> <div><br></div> <div>이상 없을거라고 생각했는데, 앱을 돌리다보면 간혹 페이탈이 뜨더라구요.</div> <div>로그캣과 제가찍은 로그 분석해보니</div> <div><br></div> <div>블루투스 연결이 해제되었는데 </div> <div>스레드가 제때 종료되지 않고 </div> <div>인풋스트림을 참조한것 같습니다.</div> <div><br></div> <div>제가 이해가 안가는건, </div> <div><br></div> <div>1. while문 인터럽트 검사</div> <div>-> 2. if문에서 <span style="font-size:9pt;">인풋스트림 available 메소드를 호출</span></div> <div><span style="font-size:9pt;">-> 3. 인풋스트림 read 메소드를 호출</span></div> <div><span style="font-size:9pt;">-> 4. 이 후 데이터 처리 사이클(인풋스트림 참조 없음)</span></div> <div><span style="font-size:9pt;"><br></span></div> <div><span style="font-size:9pt;">위와 같은 방식에서</span></div> <div><span style="font-size:9pt;">블루투스 통신을 해제하는 순서는 저 위에 있는것처럼 인터럽트 후에 소켓을 닫습니다.</span></div> <div><span style="font-size:9pt;">그런데 1에서 인터럽트 조건은 통과하고, </span></div> <div><span style="font-size:9pt;">2와 3에서 인풋스트림이 참조될 수 없는게(블루투스 소켓이 close) 일어난건가요?</span></div> <div><span style="font-size:9pt;"><br></span></div> <div><span style="font-size:9pt;">이런 경우 어떤 방향으로 해결을 해야할지도 조언 부탁드립니다.</span></div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.