0 votes
in Java by
How to perform two tasks by two threads? Means two threads running separately and performs task independently. Please provide suitable running example.

1 Answer

0 votes
by (4.4k points)
As we know that, Each thread run in a separate callstack.

See the following example which Two tasks performed by two threads:-

class MyThread1 extends Thread{  
 public void run(){  
   System.out.println("Task one");  
class MyThread2 extends Thread{  
 public void run(){  
   System.out.println("Task two");  
class TestMultitasking{  
 public static void main(String args[]){  
  MyThread1 t1=new MyThread1();  
  MyThread2 t2=new MyThread2();  


Task one
Task two

Share:- Whatsapp Facebook Facebook

Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.