토글 버튼을 누를 때 스레드이 시작되었습니다. 이제 해당 토글 버튼을 다시 누르면 스레드가 멈추고 싶습니다. 그러나 Thread.stop()
API는 더 이상 사용되지 않습니다. 그래서 UnsupportedOperationException이 발생합니다. 대신 TimerTask을 사용하는 방법을 모르겠다. 여기 내 샘플 코드는 다음과 같습니다.Thread.stop()은 더 이상 사용되지 않습니다. 대신 TimerTask를 사용하는 방법은?
//AudioDispatcher implements a Runnable
public class AudioDispatcher implements Runnable
//This is a code to start a thread
AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050,1024,0);
Thread t1 = new Thread(dispatcher,"Audio Dispatcher");
t1.start();
https://docs.oracle.com/javase/7/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html – Eric
가능한 [TimerTask를 사용하여 스레드를 어떻게 실행합니까?] (http : // 10029831/how-do-you-use-a-timertask-to-run-a-thread) –