How to run multiple consoles from one class?

后端 未结 5 828
一个人的身影
一个人的身影 2021-01-25 06:27

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. Wha

相关标签:
5条回答
  • 2021-01-25 06:39

    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.

    0 讨论(0)
  • 2021-01-25 06:47

    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.

    0 讨论(0)
  • 2021-01-25 06:51
    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.

    0 讨论(0)
  • 2021-01-25 06:56

    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 讨论(0)
  • 2021-01-25 07:00

    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.

    0 讨论(0)
提交回复
热议问题