Android Document文档如下所示,提到建议使用 IntentService 的 onHandleIntent()函数管理任务,而不是简单的启动一个线程来处理:
Should you use a service or a thread? A service is simply a component that can run in the background even when the user is not interacting with your application. Thus, you should create a service only if that is what you need. If you need to perform work outside your main thread, but only while the user is interacting with your application, then you should probably instead create a new thread and not a service. For example, if you want to play some music, but only while your activity is running, you might create a thread in onCreate(), start running it in onStart(), then stop it in onStop(). Also consider using AsyncTask or HandlerThread, instead of the traditional Thread class. See the Processes and Threading document for more information about threads. Remember that if you do use a service, it still runs in your application's main thread by default, so you should still create a new thread within the service if it performs intensive or blocking operations.
网上也有人说 最好在accept()blocked 的时候关闭 ServerSocket ,就不会发生SocketTimeoutException了,不知道对不对,但都是dcloud内部的io.dcloud.net.http.MiniServer$Server的处理模式,不知道能否修改,求助大拿