• Post Reply Bookmark Topic Watch Topic
  • New Topic

PipedInputStream connection to PipedOutputStream problem!  RSS feed

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

When using a PipedInputStream & PipedOutputStream, the program only seems to run when the "TABLE_NAME" is hard coded in OraPipe4.java program! so it looks like the "TABLE_NAME" must be known by the pipes at the time of connection probably?, see (<<<1.)

//------------------------Result when TABLE_NAME = "FN_LL_LN_1" (see <<<2.) is hardcoded in OraPipe4.java-------------------

args: f15-g1523dwskennellrkennelly3hlp_rdsfn_ll_ln_1dmyxsddmyxmlhvoed.datad
hvoed: f15-g1523dwskennellrkennelly3hlp_rdsfn_ll_ln_1dmyxsddmyxmlhvoed.datad
Select

fnma_ln,del_meth,liq_data,lpp_prod,acq_data,occ_stat,prj_type,refi_flg,sect_act,aqsn_dt,dorig_dt,orig_dte,frst_pay,fnma_upb,l

tv,orig_amt,orig_rte,part_pct,pt_rate,sell_no,orig_trm,plan_no,seasoned,fatypcd,lqactper,liqd_dte,actupbrm FROM

hlp_rds.FN_LL_LN_1

XML is generated ok:

end of line hit: <FATYPCD>3</FATYPCD>
end of line hit: <DEL_METH>C</DEL_METH>
end of line hit: <ACQ_DATA>N</ACQ_DATA>
end of line hit: <LIQ_DATA>N</LIQ_DATA>

//----------------------Result when i pass the TABLE_NAME to program OraPipe4.java, see (<<<3.), where TABLE_NAME = " " at the time of "pipe connection".

Select

fnma_ln,del_meth,liq_data,lpp_prod,acq_data,occ_stat,prj_type,refi_flg,sect_act,aqsn_dt,dorig_dt,orig_dte,frst_pay,fnma_upb,l

tv,orig_amt,orig_rte,part_pct,pt_rate,sell_no,orig_trm,plan_no,seasoned,fatypcd,lqactper,liqd_dte,actupbrm FROM

hlp_rds.FN_LL_LN_1
Exception in thread "main" java.io.IOException: Write end dead <<<<<<<<<<<<<<<<<
at java.io.PipedInputStream.read(PipedInputStream.java:213)
at java.io.PipedInputStream.read(PipedInputStream.java:274)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
at px5.main(px5.java:63)

 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are actually encountering a documented "feature" of the piped streams. Whenever you read or write to a pipe, the thread that does the action is saved (thread object, that is). Also prior to doing the action, the other side is checked. If the saved thread is no longer alive, it throws an IO exception.

Personally, I find this "feature" more annoying than useful, but it is documented in the JavaDocs.

Henry
[ April 25, 2005: Message edited by: Henry Wong ]
 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry!

Thanks to your suggestion, i read further into the documenation and based on a comment, i put the connect on the write end, pasing the pis & pos, and that did the trick!



 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correction, quess i left the 'hardcoded' table name in that latest test! , so still having that problem! even when i connect the pipes after loading the TABLE_NAME, wow, this is really quite a phenomena!

So back to testing and i'll give an update if/when i find anything new, and is quess in the mean time, i'm going to set up a process to compile on the fly, eg, build the program based on the input table parm, compile it and run it for every file, ie need to do this for 200+ files!

Thanks Henry!
bc
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have two options...

- Modify your writer thread to not exit prematurely -- at least until the data is read on the other side. This is of course, a problem if you have more than one writer to the pipe -- as you can have complex data structures. I do *NOT* recommend doing this.

- Modify your reader thread to ignore the IO exception. If you only have one writer, then you can assume that there is no more data to be read. If you have more than one writer, then it gets complicated. The pipe will fix itself when another writer that is alive writes to the pipe. On the read side, in the IO exception handler, just put in a small sleep, and try again, until a live writer comes onboard.

Henry
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And BTW, there was no need to call the connect() method -- as the pipes were connect during construction.

Henry
 
bob connolly
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry you are right about that!

I set up the process to build the program in pieces, ie implant the 'table_name' in the program, compile it and then run it and it seems to be working now, but i do get that excetion you're talking about and it must be when the JDBC extract finishes!

"HlpValOraBufXml2: java.io.IOException: Write end dead"

And in the PipedInputStream source i see this code:
/**
* Reads the next byte of data from this piped input stream. The
* value byte is returned as an <code>int</code> in the range
* <code>0</code> to <code>255</code>. If no byte is available
* because the end of the stream has been reached, the value
* <code>-1</code> is returned. This method blocks until input data
* is available, the end of the stream is detected, or an exception
* is thrown.
* If a thread was providing data bytes
* to the connected piped output stream, but
* the thread is no longer alive, then an
* <code>IOException</code> is thrown.
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream is reached.
* @exception IOException if the pipe is broken.
*/
public synchronized int read() throws IOException {
if (!connected) {
throw new IOException("Pipe not connected2");
} else if (closedByReader) {
throw new IOException("Pipe closed");
} else if (writeSide != null && !writeSide.isAlive()
&& !closedByWriter && (in < 0)) {
throw new IOException("Write end dead"); <<<<<<<<<<<<
}
So i'm still checking to see if i really did process all of the records and if so this will be great!

Thanks again Henry!
bc
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!