여기는 스레드를 사용하여 작성한 작은 프로그램의 스 니펫입니다.Thread not staying alive - IllegalStateException
JOptionPane.showMessageDialog(null, "Before: " + thread.isAlive());
if (!thread.isAlive()) {
JOptionPane.showMessageDialog(null, "Thread is not alive.");
thread.start();
}
JOptionPane.showMessageDialog(null, "After: " + thread.isAlive());
이 코드는 버튼을 사용하여 활성화됩니다. 처음 버튼을 누르면 "Before : false"와 "After : true"가 올바르게 표시됩니다. 버튼을 다시 누르면 "Before : false"와 "After : true"가 잘못 표시되지만 Before : true는 스레드를 파기하거나 변수를 무시하지 않기 때문입니다.
나는 이것이 내가 (내가 너무 그것에 대한 잘못된 생각하면 날 수정!)
이사람이 내가 잘못 뭐하는 거지 나에게 설명 할 수 무엇입니까 IllegalStateException이 원인이 무엇이라고 생각?
편집 :
public class SomeClass extends Applet
{
private ClassThatExtendsThread thread;
public void init()
{
super.init();
//Some UI elements are created here.
thread = new ClassThatExtendsThread (/*there are some parameters*/);
}
어디서'스레드 '를 어떻게 초기화하고 있습니까? – NPE
*이게 내가 얻고있는 IllegalStateException의 원인이라고 생각합니다 * : * this * *? 예외의 전체 스택 추적은 무엇입니까? 차라리 이것이 예외의 * 결과 *라고 말하면 스레드가 죽는 원인이 될 수 있습니다. –
스레드 클래스가 저장되고 인스턴스화되는 방법을 추가했습니다. –