Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 614124 Details for
Bug 849394
rhq-script-plugin does not always capture process output; causes spurious failures
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
optional use of a thread pool
0002-use-of-thread-pool-to-handle-IO-redirect.patch (text/plain), 6.28 KB, created by
Elias Ross
on 2012-09-18 21:08:50 UTC
(
hide
)
Description:
optional use of a thread pool
Filename:
MIME Type:
Creator:
Elias Ross
Created:
2012-09-18 21:08:50 UTC
Size:
6.28 KB
patch
obsolete
>From f9b5343e73fb930e1aa4473f91ba3256ccc19d02 Mon Sep 17 00:00:00 2001 >From: Elias Ross <elias_ross@apple.com> >Date: Sun, 19 Aug 2012 21:20:34 -0700 >Subject: [PATCH 2/2] use of thread pool to handle IO redirect > >--- > .../org/rhq/core/util/exec/ProcessExecutor.java | 25 ++++++++++---------- > .../org/rhq/core/util/exec/StreamRedirector.java | 15 ++++-------- > .../org/rhq/core/util/exec/ProcessExecTest.java | 2 +- > 3 files changed, 19 insertions(+), 23 deletions(-) > >diff --git a/modules/core/util/src/main/java/org/rhq/core/util/exec/ProcessExecutor.java b/modules/core/util/src/main/java/org/rhq/core/util/exec/ProcessExecutor.java >index 308d9bd..d072230 100644 >--- a/modules/core/util/src/main/java/org/rhq/core/util/exec/ProcessExecutor.java >+++ b/modules/core/util/src/main/java/org/rhq/core/util/exec/ProcessExecutor.java >@@ -34,6 +34,7 @@ > import java.text.SimpleDateFormat; > import java.util.Date; > import java.util.concurrent.Callable; >+import java.util.concurrent.ExecutionException; > import java.util.concurrent.ExecutorService; > import java.util.concurrent.Executors; > import java.util.concurrent.Future; >@@ -117,7 +118,7 @@ public Integer call() throws Exception { > }; > Future<Integer> future = threadPool.submit(call); > try { >- exitCode = future.get(process.getWaitForExit().intValue(), TimeUnit.MILLISECONDS); >+ exitCode = future.get(process.getWaitForExit(), TimeUnit.MILLISECONDS); > } catch (InterruptedException ie) { > // this might happen if the launching thread got interrupted > Thread.currentThread().interrupt(); >@@ -146,10 +147,10 @@ public Integer call() throws Exception { > */ > protected static class RedirectThreads { > >- private final StreamRedirector stdout; >- private final StreamRedirector stderr; >+ private final Future<?> stdout; >+ private final Future<?> stderr; > >- private RedirectThreads(StreamRedirector stdout, StreamRedirector stderr) { >+ private RedirectThreads(Future<?> stdout, Future<?> stderr) { > this.stdout = stdout; > this.stderr = stderr; > } >@@ -157,17 +158,17 @@ private RedirectThreads(StreamRedirector stdout, StreamRedirector stderr) { > /** > * Waits for output to be fully captured. > */ >- public void join() throws InterruptedException { >- stderr.join(); >- stdout.join(); >+ public void join() throws InterruptedException, ExecutionException { >+ stderr.get(); >+ stdout.get(); > } > > /** > * Interrupts these threads. > */ > public void interrupt() { >- stderr.interrupt(); >- stdout.interrupt(); >+ stderr.cancel(true); >+ stdout.cancel(true); > } > > } >@@ -216,8 +217,8 @@ protected RedirectThreads redirectStreams(ProcessToStart process, Process childP > StreamRedirector stdoutThread = new StreamRedirector(threadNamePrefix + "-stdout", stdout, fileOutputStream); > StreamRedirector stderrThread = new StreamRedirector(threadNamePrefix + "-stderr", stderr, fileOutputStream); > >- stdoutThread.start(); >- stderrThread.start(); >+ Future<?> submit = threadPool.submit(stdoutThread); >+ Future<?> submit2 = threadPool.submit(stderrThread); > > // if an input file was specified, take the file's data and write it to the process' stdin > File inputFile = getInputFile(process); >@@ -239,7 +240,7 @@ protected RedirectThreads redirectStreams(ProcessToStart process, Process childP > > stdin.close(); > >- return new RedirectThreads(stdoutThread, stderrThread); >+ return new RedirectThreads(submit, submit2); > } > > /** >diff --git a/modules/core/util/src/main/java/org/rhq/core/util/exec/StreamRedirector.java b/modules/core/util/src/main/java/org/rhq/core/util/exec/StreamRedirector.java >index afff92d..2d5ada9 100644 >--- a/modules/core/util/src/main/java/org/rhq/core/util/exec/StreamRedirector.java >+++ b/modules/core/util/src/main/java/org/rhq/core/util/exec/StreamRedirector.java >@@ -31,7 +31,7 @@ > * > * @author John Mazzitelli > */ >-public class StreamRedirector extends Thread { >+public class StreamRedirector implements Runnable { > /** > * the stream where we read data from > */ >@@ -42,6 +42,8 @@ > */ > private final OutputStream m_output; > >+ private final String name; >+ > /** > * Constructor for {@link StreamRedirector} that takes an input stream where we read data in and an output stream > * where we write the data read from the input stream. If the output stream is <code>null</code>, the incoming data >@@ -54,18 +56,12 @@ > * @throws IllegalArgumentException if input stream is <code>null</code> > */ > public StreamRedirector(String name, InputStream is, OutputStream os) throws IllegalArgumentException { >- super(name); >- >+ this.name = name; > if (is == null) { > throw new IllegalArgumentException("is=null"); > } >- >- setDaemon(true); >- > m_input = is; > m_output = os; >- >- return; > } > > /** >@@ -73,6 +69,7 @@ public StreamRedirector(String name, InputStream is, OutputStream os) throws Ill > */ > @Override > public void run() { >+ Thread.currentThread().setName(name); > final int bufferSize = 4096; > byte[] buffer = new byte[bufferSize]; > boolean keepGoing = true; >@@ -104,7 +101,5 @@ public void run() { > } > } catch (IOException e) { > } >- >- return; > } > } >\ No newline at end of file >diff --git a/modules/core/util/src/test/java/org/rhq/core/util/exec/ProcessExecTest.java b/modules/core/util/src/test/java/org/rhq/core/util/exec/ProcessExecTest.java >index 49ab3f5..60b7aed 100644 >--- a/modules/core/util/src/test/java/org/rhq/core/util/exec/ProcessExecTest.java >+++ b/modules/core/util/src/test/java/org/rhq/core/util/exec/ProcessExecTest.java >@@ -35,7 +35,7 @@ > public class ProcessExecTest { > public void testProcessExecOutputStream() { > // run multiple times to ensure race condition fixed >- for (int i = 0; i < 100; i++) { >+ for (int i = 0; i < 10; i++) { > ProcessToStart start = new ProcessToStart(); > > setupProgram(start); >-- >1.7.9.3 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 849394
:
612648
|
614123
| 614124