Commit: c56db5b68c986ceda00fcb88dd29fa5387e72e82 Author: Anatol Belski <a...@php.net> Sat, 8 Sep 2018 11:08:02 +0200 Parents: 6a8e19c7aea98a3d08f1253d25d6c66d830f2367 Branches: revamp_3
Link: http://git.php.net/?p=pftt2.git;a=commitdiff;h=c56db5b68c986ceda00fcb88dd29fa5387e72e82 Log: Remove deprecated thread handling method as it doesn't work with newer Java anymore Changed paths: M src/com/mostc/pftt/host/LocalHost.java M src/com/mostc/pftt/host/WindowsLocalHost.java Diff: diff --git a/src/com/mostc/pftt/host/LocalHost.java b/src/com/mostc/pftt/host/LocalHost.java index 08a93b5..d4eab80 100644 --- a/src/com/mostc/pftt/host/LocalHost.java +++ b/src/com/mostc/pftt/host/LocalHost.java @@ -363,7 +363,7 @@ public abstract class LocalHost extends AHost { protected InputStream stdout, stderr; protected String image_name; protected Charset charset; - protected final AtomicBoolean run = new AtomicBoolean(true), wait = new AtomicBoolean(true), timedout = new AtomicBoolean(false); + protected final AtomicBoolean wait = new AtomicBoolean(true), timedout = new AtomicBoolean(false); public LocalExecHandle(Process process, OutputStream stdin, InputStream stdout, InputStream stderr, String[] cmd_array) { this.process = new AtomicReference<Process>(process); @@ -388,13 +388,9 @@ public abstract class LocalHost extends AHost { public synchronized void close(ConsoleManager cm, final boolean force) { if (cm != null && cm.isPfttDebug()) new IllegalArgumentException().printStackTrace(); - if (!run.get()) - return; // already trying|tried to close final Process p = this.process.get(); if (p==null) return; - // @see WindowsLocalHost#exec_copy_lines - run.set(false); /*synchronized(run) { run.notifyAll(); }*/ @@ -533,7 +529,7 @@ public abstract class LocalHost extends AHost { ByLineReader reader = charset == null ? new NoCharsetByLineReader(new java.io.BufferedInputStream(in)) : new MultiCharsetByLineReader(in, d); String line; try { - while (reader.hasMoreLines()&&wait.get()&&run.get()&&(max_chars<1||sb.length()<max_chars)) { + while (reader.hasMoreLines()&&wait.get()&&(max_chars<1||sb.length()<max_chars)) { line = reader.readLine(); if (line==null) break; diff --git a/src/com/mostc/pftt/host/WindowsLocalHost.java b/src/com/mostc/pftt/host/WindowsLocalHost.java index 6a21e83..9c61932 100644 --- a/src/com/mostc/pftt/host/WindowsLocalHost.java +++ b/src/com/mostc/pftt/host/WindowsLocalHost.java @@ -145,7 +145,6 @@ public class WindowsLocalHost extends LocalHost { } } - @SuppressWarnings("deprecation") protected void exec_copy_lines(final StringBuilder sb, final int max_chars, final InputStream in, final Charset charset) throws IOException { final AtomicBoolean copy_thread_lock = new AtomicBoolean(true); Thread copy_thread = TimerUtil.runThread("ExecCopyLines", new Runnable() { @@ -153,7 +152,6 @@ public class WindowsLocalHost extends LocalHost { try { do_exec_copy_lines(sb, max_chars, in, charset); copy_thread_lock.set(false); - run.set(false); /*synchronized(run) { run.notifyAll(); }*/ @@ -165,6 +163,9 @@ public class WindowsLocalHost extends LocalHost { } }); copy_thread.setUncaughtExceptionHandler(IGNORE_EXCEPTION_HANDLER); + /* TODO do_exec_copy_lines would normally throw an IO exception on failed operation. As the run flag is removed, + it might be still to check whether no additional thread handling is required. Possibly no separate thread + is required at all with newer Java. */ while (wait.get()) { //synchronized(run) { try { @@ -172,16 +173,7 @@ public class WindowsLocalHost extends LocalHost { Thread.sleep(300); } catch ( InterruptedException ex ) {} //} - if (!run.get()) { - // try killing copy thread since its still running after it was supposed to stop - copy_thread.stop(new RuntimeException() { - @Override - public void printStackTrace() { - - } - }); - break; - } else if (!copy_thread_lock.get()) { + if (!copy_thread_lock.get()) { // stopped normally break; }