public CommandServiceImpl() { //线程初始化 thread = new Thread(CommandServiceImpl.class.getName()) { @Override public void run() { while (thread == this && !this.isInterrupted()) { if (commandExecutors != null && commandExecutors.size() > 0) { lock.lock(); LogUtil.i(TAG, "Executors Size:" + commandExecutors.size()); for (CommandExecutor executor : commandExecutors) { if (executor.isTimeOut()) try { killSelf(); } catch (RemoteException e) { e.printStackTrace(); } if (thread != this && this.isInterrupted()) break; } lock.unlock(); } try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } } } }; thread.setDaemon(true); thread.start(); }//源代码片段来自云代码http://yuncode.net /** * 杀掉自己 * * @throws RemoteException */ @Override public void killSelf() throws RemoteException { android.os.Process.killProcess(android.os.Process.myPid()); }//源代码片段来自云代码http://yuncode.net