简体   繁体   中英

How can i allow three threads accessing three different consoles in java?

So i am trying to build a simple application to show concurrency in java. I wanna open 3 console windows so that i can get input output from all of them. How can do this?

Edit:I have 3 threads, each thread has its own set of cache. I wanna run 3 consoles separately in java. i opened command prompt using Runtime class and tried attaching input and outputstream to it. But failed writing or reading from that newly opened console.

In most OSes, a process can open only one console.

You could create multiple processes and communicate between them , but that would show interprocess communication rather than inter-thread communication.

On Windows, you could try spawning child processes using 'more' or 'copy con' commands and writing to their input stream, or run your own java client which just echos input to output.

You could also create multiple JFrames and record the output of the threads in them, but again a given process has to do all its swing updates in the one swing thread, so the different threads have to sync when they output.

You're probably better off writing to the same console with different prefixes; output to the screen is always going to be a single thread in current OSes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM