jjzjj

StopRequest

全部标签

java - 从另一个线程读取共享变量(Effective Java #66)

在EffectiveJava:第66条中,JoshuaBloch举了一个关于人生失败的例子://Broken!-HowlongwouldyouexpectthisprogramtorunclassStopThread{privatestaticbooleanstopRequested=false;publicstaticvoidmain(String[]args)throwsInterruptedException{ThreadbackgroundThread=newThread(newRunnable(){publicvoidrun(){inti=0;while(!stopReque

Android:使用处理程序和 postDelayed() 发出问题

我正在尝试使用处理程序让一些代码在一定时间内执行。这在我的两个类(class)中效果很好,但我遇到了这个问题:我的一个类扩展了Activity,并启动了一个Thread(实现了Runnable)。在我的run()方法中,与在其他类中一样:mHandler=newHandler();mHandler.removeCallbacks(StopRequest);mHandler.postDelayed(StopRequest,30000);程序似乎在提示:java.lang.RuntimeException:Can'tcreatehandlerinsidethreadthathasnotca