那里的线程的runnable看起来像这样
Runnable mTask = new Runnable()
{
public void run()
{
Log.v("service", "thread is running after 5 min");
// Normally we would do some work here... for our sample, we will
// just sleep for 30 seconds.
long endTime = System.currentTimeMillis() + 15*1000;
while (System.currentTimeMillis() < endTime)
{
synchronized (mBinder)
{
try
{
mBinder.wait(endTime - System.currentTimeMillis());
}
catch (Exception e)
{
}
}
} // Done with our work... stop the service!
AlarmService_Service.this.stopSelf();
}
}
我承认我对同步的概念有一些问题......线程运行while循环等待15s,在那个循环中我等待15s。那么如果我只想写一个日志条目,例如 Log.v(TAG,TEXT);,runnable 会是什么样子?如果我想在我自己的数据库表中写入一个新条目,会发生什么变化?
谢谢。