Author |
Message
|
Biju |
Posted: Tue Nov 22, 2005 3:09 am Post subject: |
|
|
 Acolyte
Joined: 03 Oct 2005 Posts: 71
|
Hi Guys,
Sorry to post in a dead thred. But I would like to know why is and integer used in the folowing code
Quote: |
int i = 0;
while ((i = fileInput.read()) != -1) {
m.write(i); |
Is there any specific reason for it. Can't we use a bye[] and read the whole file at once which will improve perfomance. Just a thought...if any one interested please explain or correct me.
Regards,
Bijish |
|
Back to top |
|
 |
Tibor |
Posted: Tue Nov 22, 2005 5:47 am Post subject: |
|
|
 Grand Master
Joined: 20 May 2001 Posts: 1033 Location: Hungary
|
Biju,
There would be some contact admin side-effect when you read the full file content without knowing its real length
Tibor |
|
Back to top |
|
 |
Biju |
Posted: Tue Nov 22, 2005 9:02 pm Post subject: |
|
|
 Acolyte
Joined: 03 Oct 2005 Posts: 71
|
Hello Tibor,
Thank you for your reply...but how about this code segment.....
Quote: |
FileInputStream inputFile = new FileInputStream(file);
int filesize = inputFile.available();
byte[] b = new byte[filesize];
int i = 0;
while ((i = inputFile.read(b)) != -1)
{
msg.write(b);
}
queue.put(msg, putMsgOption);
qMgr.commit(); |
Here we will get the length and hence I guess it should work fine. What do you think? In fact it makes the program atleast 100 times faster if the file size is in MBs....wouldnt it? Any corrections will be apreciated. Thank you again.
Regards,
Bijish |
|
Back to top |
|
 |
Tibor |
Posted: Thu Nov 24, 2005 5:22 am Post subject: |
|
|
 Grand Master
Joined: 20 May 2001 Posts: 1033 Location: Hungary
|
Code: |
byte[] b = new byte[filesize]; |
I find it very harmful, when a user starts your program with a huge file. This will cause a pretty memory allocation error I recommend you to consider the max message length (depend on queue and/or channel) and re-think this application.
HTH,
Tibor |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Nov 25, 2005 5:46 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20763 Location: LI,NY
|
As well if you are worried about performance check java.nio.*. This is the fastest way to handle files (need java 1.4 or above).
Enjoy  |
|
Back to top |
|
 |
arfinn |
Posted: Wed Apr 12, 2006 3:31 am Post subject: Re: Segmentation problem: message too large |
|
|
Newbie
Joined: 12 Apr 2006 Posts: 1
|
hopsala wrote: |
pawanwatt_008 wrote: |
Just change the value (Increase to some upper limit) of MAXMSGL on Server connection channel. Then it works like a breeze. |
?!
Dude/t, did you look at the date? This thread is dead and buried. Not only that, but your answer was off the mark - he specifically stated "since I'm attempting to do segmentation". Please don't post unnecessarily  |
Stupid as it sounds, this is the correct answer; I found this thread through a google search an it helped to fix my own program.
Note that only the channel to the server needs the MAXMSGL increased, neither the queuemanager nor the queue have to be touched.
sorry if this is answered else where.... |
|
Back to top |
|
 |
|