Let's say I have something like this:
What could I do to end Thread t where indicated?Code:public class UsingThreads { /** * @param args */ public UsingThreads(){ Thread t = new Thread(new Thread1Class()); t.start(); try{ Thread.sleep(2000); // WANT TO END THREAD HERE************** //************************************** }catch(Exception e){ System.out.println("Error: " + e.getMessage()); } } public static void main(String[] args) { new UsingThreads(); } class Thread1Class extends Thread{ public void run(){ while(true){ System.out.println("Still Running..."); try{ Thread.sleep(500); }catch(Exception e){ System.out.println(e.getMessage()); } } } } }




Reply With Quote