/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package threadexample; /** * * @author karlssoj */ public class Main implements Runnable { /** * @param args the command line arguments */ public static void main(String[] args) throws InterruptedException { //huvutråden Thread minTrad = new Thread(new Main()); minTrad.start(); int counter = 0; while(true) { System.out.println("Huvutråden"); Thread.sleep(1000); if(counter >= 3) { minTrad.interrupt(); } counter++; } } public void run() { //throw new UnsupportedOperationException("Not supported yet."); while(true) { System.out.println("Ny tråd"); try { Thread.sleep(2000); } catch(InterruptedException fel) { System.out.println("Fel uppstod: " + fel.getMessage()); break; } } } }