---
title: "Android开发：如何安全的中止一个自定义线程Thread"
author: "rys5851968"
date: "2013-02-15T16:37:00Z"
tags: []
slug: "android-thread"
draft: false
lastmod: "2013-03-04T08:35:58Z"
id: 1820744
url: "https://rys1314520.iteye.com/blog/1820744"
---

经研究，我推荐这种写法：

```
/*自定义线程*/
	class MyThread implements Runnable{

		public void run() {
			// TODO Auto-generated method stub
// 定义自己的变量
 while(!Thread.currentThread().isInterrupted()){
				try { 
 doSomeThingNeed();//需要更新的操作  
 //休眠控制最大帧率为每秒3绘制30次
					Thread.sleep(30);
					
				} catch (Exception e) {
					// TODO: handle exception
					Log.v(tag2, "DrawSurfaceView：绘制失败...");
					Thread.currentThread().interrupt();
				}	
				
				
				
			}
			
		}
```

这种写法比http://blog.csdn.net/yanzi1225627/article/details/8581200[用 一个标志位的方法 停止线程更方便！](http://blog.csdn.net/yanzi1225627/article/details/8581200)