怎么把一個線程停止掉? 現在我用stop()這個方法停止線程﹐但這個方法已經過時了﹐而且會拋一個異常。如果不用stop()停止線程還有其它方法嗎? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void interrupt()中断线程。 具体的看API文档。 我有看API﹐中斷線程以后再重新啟動線程還是用start()嗎? Yes you are right! package haha;public class ThreadDemo {public static void main(String [] args) { TestThread Test =new TestThread(); Test.start(); Test.interrupt(); Test.start(); Test.interrupt(); }}class TestThread extends Thread{ public void run() { System.out.println("run:"+Thread.currentThread().getName()); }}报错呀 boolean b=true;while(b){ public void run(){}}在主线程里控制b的值.如果想中断的话.改成false 刚开始学java,对楼上说的不是很明白,有人给详细解释一下么~ 谢谢了~ 上面写错了,看看这个!应该没问题!class TextThread{ public static void main(String args[]){ MyThread t=new MyThread(); t.start(); }}class MyThread extends Thread{ int i=0; public void run(){ while(i<10){ System.out.println("I'm here!"+(i++)); }}} 先interrupt那个线程 然后在线程所在的run方法中捕获异常 最后在catch中return; Java编写界面 关于时间格式化问题 被杠晕了! 求图片优化或压缩包 Hibernate如何解决多单条件或多条件进行模糊查询? List(菜鸟问题) JCreator怎么输入命令行参数?? 新手的问题 那里 JSDK 2.0 下载!!完整地址!! 200分就给你 请教各位高手!!!--关于SWING 类库 小弟出学 请同学们帮我解决一下
you are right!
public static void main(String [] args)
{
TestThread Test =new TestThread();
Test.start();
Test.interrupt();
Test.start();
Test.interrupt();
}
}class TestThread extends Thread
{
public void run()
{
System.out.println("run:"+Thread.currentThread().getName());
}
}
报错呀
while(b){
public void run(){}
}
在主线程里控制b的值.如果想中断的话.改成false
上面写错了,看看这个!应该没问题!
class TextThread
{
public static void main(String args[]){
MyThread t=new MyThread();
t.start();
}
}class MyThread extends Thread
{
int i=0;
public void run()
{
while(i<10){
System.out.println("I'm here!"+(i++));
}}
}