는 그것이 청각 장애 지연
자바의 콘솔 출력을해야합니다 프로그램을 차단할 수 있도록 잠재적으로 코드가 특히 많은 양의 데이터를 기록 할 때, 차단할 수, blocking입니다.
tty 메모리의 크기는 얼마입니까?
내가 그것을 커널에 달려 있다는 확신이 old thread는 4096 바이트 어떤 순간 것을 제안한다 : 나는 (커널 코드에서 봤는데
리눅스 \ 드라이버 \ 문자 \ serial.c) 그리고 SERIAL_XMIT_SIZE라는 #define이 있습니다. 처음에 나는 아마도 그것을 바꿀 수 있다고 생각했는데, 실제로 송신 버퍼가 메모리 페이지 (4k)로 고정되어있는 것 같습니다. 나는 잠시 동안 연결이 끊어 질 경우
- 아직도 실행?
예, 아무도 tty에 연결되어 있지 않으면 데이터를 삭제할 수 있으므로 훨씬 빠르게 실행됩니다.
또한 사용 사례를 시뮬레이트하는 작은 테스트 응용 프로그램입니다.
Echo.java
import java.io.IOException;
public class Echo {
public static void main(String[] args) throws InterruptedException, IOException {
final byte[] data = new byte[Test.BODY_LENGTH + Test.END_MARKER.length];
int index = 0;
outer: while (true) {
data[index++] = (byte) System.in.read();
final int dataOffset = index - Test.END_MARKER.length;
if (dataOffset < 0) {
continue;
}
for (int i = 0; i < Test.END_MARKER.length; i++) {
if (data[dataOffset + i] != Test.END_MARKER[i]) {
continue outer;
}
}
System.out.print(new String(data, 0, index));
return;
}
}
}
Test.java
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
public class Test {
public static final byte[] END_MARKER = "$TERMINATE$".getBytes();
public static final int BODY_LENGTH = 1024768;
public static void main(String[] args) throws IOException, InterruptedException {
StringBuilder data = new StringBuilder();
for (int i = 0; i < BODY_LENGTH; i++) {
data.append((char) ('a' + ThreadLocalRandom.current().nextInt(('z' - 'a' + 1))));
}
final Process process = new ProcessBuilder("java", Test.class.getPackage().getName() + ".Echo")
.directory(new File("out/production/week 3")) // Change to your output directory
.start();
process.getOutputStream().write(data.toString().getBytes());
process.getOutputStream().write(END_MARKER);
process.getOutputStream().flush();
System.out.println("Written!");
final boolean exitedAfterWroteData = process.waitFor(5, TimeUnit.SECONDS);
System.out.println(exitedAfterWroteData ? "Complete" : "Running"); // Will print running after 5 seconds
int read = 0;
while (process.getInputStream().read() > -1) {
read++;
}
if (read != data.toString().getBytes().length + END_MARKER.length) {
throw new IllegalStateException("Expected echo to print exactly " + BODY_LENGTH + END_MARKER.length + " symbols!");
}
final boolean exitedAfterWeReadData = process.waitFor(50, TimeUnit.MILLISECONDS);
System.out.println(exitedAfterWeReadData ? "Complete" : "Running"); // Will print complete after a few milliseconds
}
}
이 질문은 당신이 더 많은 예시를 같이 지정하거나 데이터 유형에 대해 설명하고 당신이 정확하게 수행하려고 할 수 있습니다 너무 광범위? –
데이터 유형? PrintStream은 문자열만을 출력합니까? 이 질문은 자바에 관한 것이 아니라 TTY와 콘솔에 관한 것입니다. – UPvoter