java中如何终止线程 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 设置一个布尔变量running,初始化为false;在start()方法中,将running置为true;提供一个公用的方法halt(),将running变量置为false;在run()方法中使用类似的while循环: public void run(){ while(running) { /*线程要执行的代码*/} }stop()方法在jdk较新的版本中建议不在使用 使用 Thread.interrupt()方法来跳出阻塞代码;建议楼主给出你的程序。。那样好分析些^-^ public class CalculateThread extends Thread{ private EntityDataRetrieveCondition conditions = null; public CalculateThread(EntityDataRetrieveCondition conditions){ this.conditions = conditions; } public void run(){ 向后台发送计算请求 } }CalculateThread calculation = null; calculation = new CalculateThread(conditions); try { calculation.suspend();// ((ThreadPoolServiceImpl)this.getCommandContext().getContext().lookup("svc:threadpool")).cancelPending(calculation);// calculation.stop();// calculation.destroy();// ((ThreadPoolServiceImpl)this.getCommandContext().getContext().lookup("svc:threadpool")).destroy();// Thread.interrupted(); System.out.println(calculation.isAlive()); calculation.interrupt(); System.out.println(calculation.isAlive());// System.out.println(Thread.activeCount() + "========="); System.gc(); System.out.println(Thread.activeCount() + "=========");// } catch (NamingException e) {// FILELOGGER.info(this.getClass().toString() + " : " + e);// } return; 后台计算???不是多线程??? 想结束的话,就调用 interrupt(); JAVA+MYSQL的库存余量判断,求思路~ 求助:Socket 编程中如何建立远程连接 怎么做一个可视的数组比较程序 求 :jbuider X 使用手册 请介绍下BlueJ 我最近想作一些網絡開發﹐各位高手能不能提供一些關於snmp的資源和開發心得啊? JAVAMAIL的内存泄露问题 新手求助 关于"+"的小问题 装了JBuilder5,怎么无法运行呢? dos调用中为什么不能返回dir的结果 大侠们来帮忙看看这个IO异常:系统找不到指定路径
在start()方法中,将running置为true;
提供一个公用的方法halt(),将running变量置为false;
在run()方法中使用类似的while循环: public void run(){
while(running)
{
/*线程要执行的代码*/}
}stop()方法在jdk较新的版本中建议不在使用
private EntityDataRetrieveCondition conditions = null;
public CalculateThread(EntityDataRetrieveCondition conditions){
this.conditions = conditions;
}
public void run(){
向后台发送计算请求 }
}CalculateThread calculation = null;
calculation = new CalculateThread(conditions);
try {
calculation.suspend();
// ((ThreadPoolServiceImpl)this.getCommandContext().getContext().lookup("svc:threadpool")).cancelPending(calculation);
// calculation.stop();
// calculation.destroy();
// ((ThreadPoolServiceImpl)this.getCommandContext().getContext().lookup("svc:threadpool")).destroy();
// Thread.interrupted();
System.out.println(calculation.isAlive());
calculation.interrupt();
System.out.println(calculation.isAlive());
// System.out.println(Thread.activeCount() + "=========");
System.gc();
System.out.println(Thread.activeCount() + "=========");
// } catch (NamingException e) {
// FILELOGGER.info(this.getClass().toString() + " : " + e);
// }
return;
想结束的话,就调用 interrupt();