- 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.
2: Create two java programs.
ClassOne:
- package com.instanceofjava;
- public class ClassOne {
- /**
- * @author www.Instanceofjava.com
- * @category interview questions
- *
- * Description: how to run two java programs simultaneously
- *
- */
- public static void main(String[] args) throws InterruptedException {
- for (int i = 0; i < 100; i++) {
- Thread.sleep(1000);
- System.out.println(i);
- }
- }
- }
ClassTwo
- package System.out;
- public class ClassTwo {
- /**
- * @author www.Instanceofjava.com
- * @category interview questions
- *
- * Description: how to run two java programs simultaneously
- *
- */
- public static void main(String[] args) throws InterruptedException {
- for (int i = 100; i < 200; i++) {
- System.out.println(i);
- Thread.sleep(1000);
- }
- }
- }
- You can see both the running programs with output with different console views.
No comments