We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

Lost messages while reading a pipefile using java

Last Modified: 2020-11-05
I have this weirdest problem...

I am using unix pipefiles to communicate between programs.

The program runs fine, only out of 200000! msgs dayly, I loose about 15.

With lost I mean:
I see this in the log of the sending program:
send2pipe : 12456478798|#|TBB|#||#|363|#|28186|#|2818600|#|400|#|0|#|N|#|JT|#|N|#|P|#||#||#||#|16|#|5|#||#|0.000000|#|26941549169310|#||#||#||#|1|#|TBB|#|N|#|2814400|#|01152|#|0|#|N|#|Y|#||#||#|END successfully passed to fifo
I see nothing in the log of the receiving program.  While the receiving program writes out the message on the very first occasion after the read.

This is very odd if you keep in mind, that a pipefile that is not read out, blocks the writing program.  But that isn't happening, the writing program says the pipe has been read.  But there is no sign of the message however in the reading program.  Also no error or whatsover.

Any hint on where those messages go would be awsome...

Here are the program snippets:

On unix I create a pipe like this:
mkfifo /data/pipe/pipefileToJava

Then in a script I write to the pipefile like this:
  echo send2pipe : sending stream $Payload to $PipeFile
  echo $Payload >  $PipeFile &
  sleep 1

    if kill %1 >/dev/null 2>&1
        echo send2pipe : could not connect to pipe
        echo send2pipe : "$Payload" successfully passed to fifo
        exit 0

Then in Java I read the pipefile in a loop like this:
It opens the file:
               fr=new FileReader(s_named_pipe_path);
               br=new BufferedReader(fr);
The java code 'hangs' on the 
Until there is a message.  It reads it, logs it.
logger.info("Retrieving a message ..." + line);
And it closes the file:

Then it goes to the top of the loop, to reopen the pipefile.
I close and reopen the pipefile everytime, otherwise I do not have that 'hanging/sleeping' waiting for message effect on the pipefile.

               fr=new FileReader(s_named_pipe_path);
               br=new BufferedReader(fr);
                   logger.info("Retrieving a message (count since start: "+ (NumberMessagesReceived++) + ") from named pipe: " + s_named_pipe_path + ": " + line);
                  logger.info("Closing file reader");
                  logger.info("Closing buffered reader");

Watch Question
This problem has been solved!
Unlock 1 Answer and 17 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE