赞
踩
public void run() { while(true){ someWork(); if(finished){ break; } try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } }}
public class Thread1 extends Thread { @Override public void run() { while(true) { try { doSomeWork(); if (finished) { break; } // wait for some resource } catch (InterruptedException e) { // ... break; } } }}public class Thread2 extends Thread { @Override public void run() { while(true) { try { doSomeWork(); if (finished) { break; } // wait for some resource } catch (InterruptedException e) { // ... break; } } }}
public abstract class AbstractThread extends Thread { protected AtomicBoolean isRunning = new AtomicBoolean(true); public void stopRunning() { isRunning.set(false); }}
while(isRunning) { ...}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。