< prev index next >

test/jdk/java/lang/ProcessBuilder/Basic.java

Print this page
rev 59105 : imported patch corelibs


2123 
2124                                 } else {
2125                                     System.out.write(bytes, 0, r);
2126                                 }
2127                                 for (int c = s.read(); c >= 0; c = s.read())
2128                                     System.out.write(c);
2129                                 System.out.println("\nEND Child output.");
2130                             }
2131                             equal(-1, r);
2132                         } catch (IOException ioe) {
2133                             if (!ioe.getMessage().equals("Stream closed")) {
2134                                 // BufferedInputStream may throw IOE("Stream closed").
2135                                 unexpected(ioe);
2136                             }
2137                         } catch (Throwable t) { unexpected(t); }}};
2138 
2139                 thread.start();
2140                 latch.await();
2141                 Thread.sleep(10);
2142 
2143                 String os = System.getProperty("os.name");
2144                 if (os.equalsIgnoreCase("Solaris") ||
2145                     os.equalsIgnoreCase("SunOS"))
2146                 {
2147                     final Object deferred;
2148                     Class<?> c = s.getClass();
2149                     if (c.getName().equals(
2150                         "java.lang.ProcessImpl$DeferredCloseInputStream"))
2151                     {
2152                         deferred = s;
2153                     } else {
2154                         Field deferredField = p.getClass().
2155                             getDeclaredField("stdout_inner_stream");
2156                         deferredField.setAccessible(true);
2157                         deferred = deferredField.get(p);
2158                     }
2159                     Field useCountField = deferred.getClass().
2160                         getDeclaredField("useCount");
2161                     useCountField.setAccessible(true);
2162 
2163                     while (useCountField.getInt(deferred) <= 0) {
2164                         Thread.yield();
2165                     }
2166                 } else if (s instanceof BufferedInputStream) {
2167                     // Wait until after the s.read occurs in "thread" by
2168                     // checking when the input stream monitor is acquired
2169                     // (BufferedInputStream.read is synchronized)
2170                     while (!isLocked(s, 10)) {
2171                         Thread.sleep(100);
2172                     }
2173                 }
2174                 p.destroy();
2175                 thread.join();
2176             }
2177         } catch (Throwable t) { unexpected(t); }
2178 
2179         //----------------------------------------------------------------
2180         // Check that subprocesses which create subprocesses of their
2181         // own do not cause parent to hang waiting for file
2182         // descriptors to be closed.
2183         //----------------------------------------------------------------
2184         try {
2185             if (Unix.is()
2186                 && new File("/bin/bash").exists()




2123 
2124                                 } else {
2125                                     System.out.write(bytes, 0, r);
2126                                 }
2127                                 for (int c = s.read(); c >= 0; c = s.read())
2128                                     System.out.write(c);
2129                                 System.out.println("\nEND Child output.");
2130                             }
2131                             equal(-1, r);
2132                         } catch (IOException ioe) {
2133                             if (!ioe.getMessage().equals("Stream closed")) {
2134                                 // BufferedInputStream may throw IOE("Stream closed").
2135                                 unexpected(ioe);
2136                             }
2137                         } catch (Throwable t) { unexpected(t); }}};
2138 
2139                 thread.start();
2140                 latch.await();
2141                 Thread.sleep(10);
2142 
2143                 if (s instanceof BufferedInputStream) {























2144                     // Wait until after the s.read occurs in "thread" by
2145                     // checking when the input stream monitor is acquired
2146                     // (BufferedInputStream.read is synchronized)
2147                     while (!isLocked(s, 10)) {
2148                         Thread.sleep(100);
2149                     }
2150                 }
2151                 p.destroy();
2152                 thread.join();
2153             }
2154         } catch (Throwable t) { unexpected(t); }
2155 
2156         //----------------------------------------------------------------
2157         // Check that subprocesses which create subprocesses of their
2158         // own do not cause parent to hang waiting for file
2159         // descriptors to be closed.
2160         //----------------------------------------------------------------
2161         try {
2162             if (Unix.is()
2163                 && new File("/bin/bash").exists()


< prev index next >