• In some cases we may need to run two java programs simultaneously and need to observe the ouput of two progarsms. In such cases we need to run multiple java programs parallel.  
  • Now we will see how to run two java programs simultaneously
  • First thing we need to understand is we can run multiple java programs at a time in eclipse.
  • Second thing is we can view multiple consoles in eclipse.   



#1. How can we open multiple consoles in eclipse?

  • In Eclipse console window right side we will have one rectangular box with Plus symbol on it to open a new console. by clicking on it we can open a new console view.

open multiple consoles  view in eclipse


2: Create two java programs.

ClassOne:
  1. package com.instanceofjava;

  2. public class ClassOne {
  3. /**
  4. * @author www.Instanceofjava.com
  5. * @category interview questions
  6. * Description: how to run two java programs simultaneously
  7. *
  8. */
  9. public static void main(String[] args) throws InterruptedException {

  10. for (int i = 0; i < 100; i++) {
  11. Thread.sleep(1000);
  12. System.out.println(i);
  13. }
  14. }
  15. }

ClassTwo
  1. package System.out;

  2. public class ClassTwo {
  3. /**
  4. * @author www.Instanceofjava.com
  5. * @category interview questions
  6. * Description: how to run two java programs simultaneously
  7. *
  8. */
  9. public static void main(String[] args) throws InterruptedException {
  10. for (int i = 100; i < 200; i++) {
  11. System.out.println(i);
  12. Thread.sleep(1000);
  13. }


  14. }

  15. }


  • Run ClassOne and ClassTwo.
  • Pin console.

pin console.png



  • You can see both the running programs with output with different console views.
how to run two java programs simultaneously

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu