public class T2 implements Runnable { private boolean active = true; private boolean alive = true; private Thread thread = null; private Multitradning callerObj = null; /** * Another thread @param callerObj reference to mainclass so taskPerformed() can be called */ public T2(Multitradning callerObj) { thread = new Thread(this); this.callerObj = callerObj; thread.start(); } public void run() { while (alive) { while (active) { try { Thread.sleep(1000); } catch (InterruptedException e) { // Nothing } callerObj.taskPerformed("T2: Tråd 2"); } try { Thread.sleep(25); } catch(InterruptedException ie) { // Nothing } } } /** * Sätter tråden aktiv (pausar) eller oaktiv * @param active om den ska vara aktiv eller ej */ public void setActive(boolean active) { this.active = active; } /** * Dödar tråden helt */ public void killThread() { this.alive = false; this.active = false; } }