Java program to perform multiple tasks by multiple threads
KW.java
class task1 extends Thread
{
    public void run()
    {  
        System.out.println("\nTask-1");  
    }
    public void inc()
    {
        for(int i=100;i<=105;i++)
        {
            System.out.print(i+" ");     
        }  
    } 
}
class task2 extends Thread
{
    public void run()
    {  
        System.out.println("\nTask-2");  
    } 
}

class KW 
{  
    public static void main(String args[])
    {  
        task1 t1=new task1();
        task2 t2=new task2(); 
        t1.inc();
        t1.start();
        t2.start(); 
    }  
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW 100 101 102 103 104 105 Task-1 Task-2 kodingwindow@kw:~$
Advertisement