it seems all stop methods of thread have been deprecated by java. so how to stop a thread then? it is actually simple, just use a boolean variable.
public class Test extends Thread{ public boolean running= true; public void shut(){ running= false; } public void run(){ while(running){ /*your method goes here*/ } } }
时间: 2024-10-11 12:39:47