현재 완료된 문자열은 System.out.println()
을 사용하여 여러 개의 실행 가능 클래스가 있습니다.스레드에서 출력 스트림을 얻는 방법
main()
에서는 ExecutorService 인 executor.execute()
을 사용하여 실행합니다. 나는 그 스레드를 실행 한 후 궁금
, how to get the output stream from them for future use ?
꽤 많은 프로세스 .getInputStream
를 사용하지만, Thread 클래스에서 그런 방법은 없다있다. 감사!
public class A implements Runnable {
public void run() {
System.out.println(5); //this thread always print out number 5
}
}
과 주요 기능에 내가 인쇄 된 번호를하고 저장해야
이public static void main(String[] args) {
ExecutorService ThreadPool = Executors.newFixedThreadPool(1);
ThreadPool.execute(new A()); //This statement will cause the thread object A
//to print out number 5 on the screen
ThreadPool.shutdown();
......
}
지금은 인쇄하는 데 필요한 :
이 같은 실행 가능한 인터페이스를 구현하는 클래스가있다 숫자 5를 만들고이를 정수 변수에 저장하십시오.
는 부모 프로세스의 과정과 동일 출력 스트림에 기입 스레드하지 않습니다,이 이후 자연적인 것 그들은 메모리를 공유하며, 자연스럽게 기본 파일 기술자를 공유합니다. – luk32
나는 꽤 이해하지 못합니까? 각 스레드는 System.out.println()을 사용하여 출력합니다. – Austin
출력 스트림이 공유 리소스가 아니므로 한 번에 하나의 스레드에서 액세스해야합니다. 틀렸을 수 있습니다. – ha9u63ar