I dont understand why the Arduino won't wait until their is no data left on the output stream before sending more data.
Serial communication is asynchronous. That means that one side does not wait for the other side. It works like a postal system. I can send you a letter. I can wait a couple days, and send you another letter. Then, I could wait for you to reply to both letters before sending another one.
You could reply to the first letter, and then reply to the second letter, or you could wait until you got both letters, and reply to both in one letter.
If you want the Arduino to wait until the Java application has processed the first packet, you can do that.
Have the Arduino send a packet. Then, have it wait for a reply from the Java application.
Have the Java application send a message when it has completed processing a packet.