/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package exempel3;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author karlssoj
 */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


/**
 *
 * @author karlssoj
 */
public class Main
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        // TODO code application logic here
        new Tradtest();
    }

}

class Tradtest implements Runnable
{
    public Tradtest()
    {
		Thread nyTrad = new Thread(this);
            nyTrad.start();
    
        	for(int i = 0; i < 5; i++)
        	{
            	try 
			{
                		System.out.println("Detta är tråd nr 1\n");
                		Thread.sleep(500);
            	} 
			catch (InterruptedException ex) 
			{
                		Logger.getLogger(Tradtest.class.getName()).log(Level.SEVERE, null, ex);
            	}
		}

		//Skickar ett avbrått till nyTrad
		nyTrad.interrupt();
    }

    public void run()
    {
        for(int i = 0; i < 10; i++)
        {
            System.out.println("Detta är tråd nr 2\n");
            
		try 
		{
            	Thread.sleep(500);
            }
            catch (InterruptedException ex)	//Ifall sleep-funktionen ger ifrån sej "IntterruptedException" skall denna tråd avsluta
            {
               	System.out.println("Någon skickade ett avbrott! Jag stänger av mej själv...");
               	break;
            }
        }
    }
}
