* Question about Thread.sleep(1000) in java.io.PipedStream close.java code
@ 2003-09-19 20:41 Patrick Ellis
2003-10-14 12:37 ` Brian Jones
0 siblings, 1 reply; 2+ messages in thread
From: Patrick Ellis @ 2003-09-19 20:41 UTC (permalink / raw)
To: mauve-discuss
I have a question about the Thread.sleep(1000) command in the close.java code. The delay does not seem long enough
On an R64 machine that I'm testing. When I change the code to Thread.sleep(100) the code seems to delay long enough for execute the code.
Is this correct ?
1 // Tags: JDK1.0
2
3 // This test is from Jeff Sturm.
4 // It tests whether close() on a PipedInputStream will correctly
5 // notify the writer.
6
7 package gnu.testlet.java.io.PipedStream;
8
9 import gnu.testlet.Testlet;
10 import gnu.testlet.TestHarness;
11 import java.io.*;
12
13 public class close implements Runnable, Testlet {
14 Thread main;
15 PipedInputStream in;
16 PipedOutputStream out;
17 TestHarness harness;
18
19 public void run() {
20 try {
21 Thread.sleep(1000);
22 harness.debug("Closing pipe input stream:");
23 in.close();
24 Thread.sleep(1000);
25 harness.debug("Interrupting pipe reader:");
26 main.interrupt();
27 } catch (Throwable t) {
28 harness.debug(t);
29 }
30 }
31
32 public void test (TestHarness harness) {
33 int val = 23;
34 try {
35 close test = new close();
36 test.harness = harness;
37
38 test.main = Thread.currentThread();
39 test.out = new PipedOutputStream();
40 test.in = new PipedInputStream(test.out);
41
42 (new Thread(test)).start();
43
44 val = test.in.read();
45 } catch (InterruptedIOException t) {
46 harness.check(true,"read() interrupted okay");
47 } catch (IOException t) {
48 harness.fail("Unexpected IOException thrown");
49 }
50 }
51 }
Pat Ellis
SAS Tools, Testing & Validation
Phone: (919) 531-0355
R2263 Patrick.Ellis@sas.com
SAS... The Power to Know
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Question about Thread.sleep(1000) in java.io.PipedStream close.java code
2003-09-19 20:41 Question about Thread.sleep(1000) in java.io.PipedStream close.java code Patrick Ellis
@ 2003-10-14 12:37 ` Brian Jones
0 siblings, 0 replies; 2+ messages in thread
From: Brian Jones @ 2003-10-14 12:37 UTC (permalink / raw)
To: Patrick Ellis; +Cc: mauve-discuss
Patrick Ellis <Patrick.Ellis@sas.com> writes:
> I have a question about the Thread.sleep(1000) command in the
> close.java code. The delay does not seem long enough On an R64
> machine that I'm testing. When I change the code to
> Thread.sleep(100) the code seems to delay long enough for execute
> the code. Is this correct ?
I think the sleep mechanism can be replaced by a wait in the test
thread and a notify in the main thread. On the whole, I don't
understand why lowering the sleep value to 100 from 1000 milliseconds
would help.
Brian
>
> 1 // Tags: JDK1.0
> 2
> 3 // This test is from Jeff Sturm.
> 4 // It tests whether close() on a PipedInputStream will correctly
> 5 // notify the writer.
> 6
> 7 package gnu.testlet.java.io.PipedStream;
> 8
> 9 import gnu.testlet.Testlet;
> 10 import gnu.testlet.TestHarness;
> 11 import java.io.*;
> 12
> 13 public class close implements Runnable, Testlet {
> 14 Thread main;
> 15 PipedInputStream in;
> 16 PipedOutputStream out;
> 17 TestHarness harness;
> 18
> 19 public void run() {
> 20 try {
> 21 Thread.sleep(1000);
> 22 harness.debug("Closing pipe input stream:");
> 23 in.close();
> 24 Thread.sleep(1000);
> 25 harness.debug("Interrupting pipe reader:");
> 26 main.interrupt();
> 27 } catch (Throwable t) {
> 28 harness.debug(t);
> 29 }
> 30 }
> 31
> 32 public void test (TestHarness harness) {
> 33 int val = 23;
> 34 try {
> 35 close test = new close();
> 36 test.harness = harness;
> 37
> 38 test.main = Thread.currentThread();
> 39 test.out = new PipedOutputStream();
> 40 test.in = new PipedInputStream(test.out);
> 41
> 42 (new Thread(test)).start();
> 43
> 44 val = test.in.read();
> 45 } catch (InterruptedIOException t) {
> 46 harness.check(true,"read() interrupted okay");
> 47 } catch (IOException t) {
> 48 harness.fail("Unexpected IOException thrown");
> 49 }
> 50 }
> 51 }
>
> Pat Ellis
> SAS Tools, Testing & Validation
> Phone: (919) 531-0355
> R2263 Patrick.Ellis@sas.com
> SAS... The Power to Know
>
>
--
Brian Jones <cbj@gnu.org>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-10-14 12:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-19 20:41 Question about Thread.sleep(1000) in java.io.PipedStream close.java code Patrick Ellis
2003-10-14 12:37 ` Brian Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).