How to run multiple consoles from one class?
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.
A certain way to do it would be to open 3 separate terminals and do
java Class<n>
(without .class extension) in each terminal.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.
精彩评论