开发者

How to run multiple consoles from one class?

开发者 https://www.devze.com 2023-04-06 05:26 出处:网络
I have three classes which all make different works but I need to run them together. When I run all of them in one class I just get one console and cant change this console. What I want is to run them

I have three classes which all make different works but I need to run them together. When I run all of them in one class I just get one console and cant change this console. What I want is to run them in one class and see each console . How can I do that ?

To be more clear ,

when I run first class, I get --> console 1
when I run secondclass, I get --> console 2
when I run third class, I get --> console 3

but instead of doing it seperatly, when I do it;

Run 1,2,3 ----> I get console 1 

The thing I want is

Run 1,2,3 ----> I get 开发者_C百科console 1, 2 and 3 

Thank you all

EDIT 1 : Sorry for not-enough info I use Eclipse to run my code, and I am talking about Eclipse console.


  1. A certain way to do it would be to open 3 separate terminals and do java Class<n> (without .class extension) in each terminal.

  2. I don't think you can do it in Eclipse with a single workspace (it could be possible though ...), one way to do it is to create separate projects for each class and open each project in a separate workspace simultaneously, but this is too much work IMO. 1. is probably the easiest/fastest way to do it.


You have to invoke java command separately for each class in different console. With one java invocation, i think, there will be only one console associated.


Obscure question. But it seems that you need separate console outputs for your classes. I don't think it is possible. That is operating system restriction. If operating system supported that you could somehow create additional consoles.

As a solution you can give your classes PrintStream object which they will use to output data.


You could run a server-like application which would accept messages and then display them in the console. The class would start each of your other main methods in new Threads, and then wait indefinitely for messages, ending when the other three threads close.


INMO, if your underlying OS is Windows then you need to handle console and use JNA or JNI that allows you to call win32APIs from java, but if your underlying OS is Unix-like then you need to find a way to communicate with syscall APIs in java. by calling native APIs you can call native console and if you know how to create a native console then you can create multiple instances of native console.

0

精彩评论

暂无评论...
验证码 换一张
取 消