我正在开发一个使用此线程运行服务的 Android 3.1 平板电脑应用程序:
public class UDPServerThread extends Thread
{
[ ... ]
public void run()
{
while (!end)
{
try
{
byte[] buf = new byte[MESSAGE_SIZE];
// Wait an incoming message.
DatagramPacket packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);
// TODO: Notify Service with packet received
Message msg = new Message();
msg.obj = packet;
mServiceHandler.sendMessage(msg);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
public void stopServer()
{
Log.v("UDPServerThread", "stopServer");
if (socket != null)
socket.close();
end = true;
}
}
stopServer()
当我从服务调用方法时,出现以下错误:
java.net.SocketException: Interrupted system call
在此线程打开时停止该线程的正确方法是socket.receive(packet);
什么?