Re: Tomcat 4.1 hangs on File Reading

2004-03-10 Thread Parsons Technical Services
Adam,

Sound very similar to a problem I had a couple of days ago. Are you using
any loops in your code? Specifically while or do-while or endless for loops.
If so try changing them to a for loop with a high count say 10k-100k and see
what happens. I had a sort method that under the right conditions would
bring down my IDE and hog all the processor.

Doug
www.parsonstechnical.com

- Original Message - 
From: Adam Buglass [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Wednesday, March 10, 2004 7:52 AM
Subject: Tomcat 4.1 hangs on File Reading


 I've got a website which members can log in and out of
 (by way of a form which connects to a JSP).

 I've created a simple method in a Java class to write to
 a text format log file to tell me stuff like who they are,
 when they logged in etc.

 So far so good.

 I'm now trying to write a JSP to analyse this log but
 when I try and access the page, tomcat usually hangs
 indefinitely. Occassionally it will display something I jtas ask
 for, say, the Strings of IDs. Tomcat will then slow right down
 (approximately 4-6x slower) and eventually need restarting.

 I've tried with a smaller test file.
 I'm closing the file connection which I open in Java.
 There doesn't appear to be anything in the logs, in fact
 neither Tomcat nor Apache appear to recognise the page request
 at all.

 Any ideas / thoughts / suggestions !?

 Thanks,
 Adam.


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Tomcat 4.1 hangs on File Reading

2004-03-10 Thread Peter Guyatt
Hi There,

This read of the file? are you doing it a character at a time (ie via the
read() method?)

If so try reading more than one charcter at a time.

Ie.

public void readFile (String filename) {
try {
File f = new File(filename);
FileReader fr = new FileReader(f);
char data[] = new char[4096];
int line = 0, read, i;
//loop until all the data is read from the stream
while ((read = fr.read(data, 0, 4096)) != -1) {
//do somthing with the data read
}
} catch (Exception e) {
e.printStackTrace();
}
}

This will dramatically improve performance and hopefully stop your problem

Thanks

Pete

-Original Message-
From: Parsons Technical Services [mailto:[EMAIL PROTECTED]
Sent: 10 March 2004 13:06
To: Tomcat Users List
Subject: Re: Tomcat 4.1 hangs on File Reading


Adam,

Sound very similar to a problem I had a couple of days ago. Are you using
any loops in your code? Specifically while or do-while or endless for loops.
If so try changing them to a for loop with a high count say 10k-100k and see
what happens. I had a sort method that under the right conditions would
bring down my IDE and hog all the processor.

Doug
www.parsonstechnical.com

- Original Message -
From: Adam Buglass [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Wednesday, March 10, 2004 7:52 AM
Subject: Tomcat 4.1 hangs on File Reading


 I've got a website which members can log in and out of
 (by way of a form which connects to a JSP).

 I've created a simple method in a Java class to write to
 a text format log file to tell me stuff like who they are,
 when they logged in etc.

 So far so good.

 I'm now trying to write a JSP to analyse this log but
 when I try and access the page, tomcat usually hangs
 indefinitely. Occassionally it will display something I jtas ask
 for, say, the Strings of IDs. Tomcat will then slow right down
 (approximately 4-6x slower) and eventually need restarting.

 I've tried with a smaller test file.
 I'm closing the file connection which I open in Java.
 There doesn't appear to be anything in the logs, in fact
 neither Tomcat nor Apache appear to recognise the page request
 at all.

 Any ideas / thoughts / suggestions !?

 Thanks,
 Adam.


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Tomcat 4.1 hangs on File Reading

2004-03-10 Thread Adam Buglass
Yes, I use a few while loops a bit like...

while (there's stuff in the file)
  while (there isn't a separator)
  while (to skip whitespace)

...etc.

Thanks, I'll try and substitute with
equivalent for loops and let you know
how I get on.

Adam.


On Wed, 2004-03-10 at 13:05, Parsons Technical Services wrote:
 Adam,
 
 Sound very similar to a problem I had a couple of days ago. Are you using
 any loops in your code? Specifically while or do-while or endless for loops.
 If so try changing them to a for loop with a high count say 10k-100k and see
 what happens. I had a sort method that under the right conditions would
 bring down my IDE and hog all the processor.
 
 Doug
 www.parsonstechnical.com
 
 - Original Message - 
 From: Adam Buglass [EMAIL PROTECTED]
 To: Tomcat Users List [EMAIL PROTECTED]
 Sent: Wednesday, March 10, 2004 7:52 AM
 Subject: Tomcat 4.1 hangs on File Reading
 
 
  I've got a website which members can log in and out of
  (by way of a form which connects to a JSP).
 
  I've created a simple method in a Java class to write to
  a text format log file to tell me stuff like who they are,
  when they logged in etc.
 
  So far so good.
 
  I'm now trying to write a JSP to analyse this log but
  when I try and access the page, tomcat usually hangs
  indefinitely. Occassionally it will display something I jtas ask
  for, say, the Strings of IDs. Tomcat will then slow right down
  (approximately 4-6x slower) and eventually need restarting.
 
  I've tried with a smaller test file.
  I'm closing the file connection which I open in Java.
  There doesn't appear to be anything in the logs, in fact
  neither Tomcat nor Apache appear to recognise the page request
  at all.
 
  Any ideas / thoughts / suggestions !?
 
  Thanks,
  Adam.
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Tomcat 4.1 hangs on File Reading

2004-03-10 Thread Adam Buglass
Currently I use readline() to get a line
and then I parse the resulting String (character by character)
to get the bits I want.

I then read the different parts into a class and return it
to a calling method which reads the class into a Vector and
returns the Vector.

This is the first method:

public static LoginLog[] readLog()throws FileNotFoundException
{
  Vector log = new Vector();

  try {
FileReader inFile = new FileReader( /var/log/GFWlogin.log );
BufferedReader bfFile = new BufferedReader( inFile );
  while ( bfFile.ready() ) {
LoginLog logentry = getLogentry( bfFile );
log.add( logentry );
  }
bfFile.close();
   } catch ( IOException e ) {} ;
   return (LoginLog[])log.toArray( new LoginLog[log.size()] );
}


The method getLogentry( bfFile ) simply reads the
line, parses the String and returns the class as I described
at the top.

Adam.



On Wed, 2004-03-10 at 13:15, Peter Guyatt wrote:
 Hi There,
 
   This read of the file? are you doing it a character at a time (ie via the
 read() method?)
 
 If so try reading more than one charcter at a time.
 
 Ie.
 
 public void readFile (String filename) {
   try {
   File f = new File(filename);
   FileReader fr = new FileReader(f);
 char data[] = new char[4096];
 int line = 0, read, i;
   //loop until all the data is read from the stream
 while ((read = fr.read(data, 0, 4096)) != -1) {
 //do somthing with the data read
   }
   } catch (Exception e) {
   e.printStackTrace();
   }
 }
 
 This will dramatically improve performance and hopefully stop your problem
 
 Thanks
 
 Pete
 
 -Original Message-
 From: Parsons Technical Services [mailto:[EMAIL PROTECTED]
 Sent: 10 March 2004 13:06
 To: Tomcat Users List
 Subject: Re: Tomcat 4.1 hangs on File Reading
 
 
 Adam,
 
 Sound very similar to a problem I had a couple of days ago. Are you using
 any loops in your code? Specifically while or do-while or endless for loops.
 If so try changing them to a for loop with a high count say 10k-100k and see
 what happens. I had a sort method that under the right conditions would
 bring down my IDE and hog all the processor.
 
 Doug
 www.parsonstechnical.com
 
 - Original Message -
 From: Adam Buglass [EMAIL PROTECTED]
 To: Tomcat Users List [EMAIL PROTECTED]
 Sent: Wednesday, March 10, 2004 7:52 AM
 Subject: Tomcat 4.1 hangs on File Reading
 
 
  I've got a website which members can log in and out of
  (by way of a form which connects to a JSP).
 
  I've created a simple method in a Java class to write to
  a text format log file to tell me stuff like who they are,
  when they logged in etc.
 
  So far so good.
 
  I'm now trying to write a JSP to analyse this log but
  when I try and access the page, tomcat usually hangs
  indefinitely. Occassionally it will display something I jtas ask
  for, say, the Strings of IDs. Tomcat will then slow right down
  (approximately 4-6x slower) and eventually need restarting.
 
  I've tried with a smaller test file.
  I'm closing the file connection which I open in Java.
  There doesn't appear to be anything in the logs, in fact
  neither Tomcat nor Apache appear to recognise the page request
  at all.
 
  Any ideas / thoughts / suggestions !?
 
  Thanks,
  Adam.
 
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
-- 

Adam Buglass,  
The Golden Freeway,
Department of Child Health,
University of Newcastle-upon-Tyne.
Royal Victoria Infirmary.

(0191) 2023062

Democracy is two wolves and a lamb voting on what to have for lunch.
Liberty is a well-armed lamb contesting the vote. 
~Benjamin Franklin, 1759


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Tomcat 4.1 hangs on File Reading

2004-03-10 Thread Ralph Einfeldt
Which jdk do you use ?

There was once a version that had an error in ready().
As far as I can remember it always returned true.

Try to end the loop also when you couldn't read a line.
(Depends on what getLogentry() does in this case)

 -Original Message-
 From: Adam Buglass [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, March 10, 2004 2:23 PM
 To: Tomcat Users List
 Subject: RE: Tomcat 4.1 hangs on File Reading
 
 FileReader inFile = new FileReader( /var/log/GFWlogin.log );
 BufferedReader bfFile = new BufferedReader( inFile );
   while ( bfFile.ready() ) {
 LoginLog logentry = getLogentry( bfFile );
 log.add( logentry );
   }
 bfFile.close();

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Tomcat 4.1 hangs on File Reading

2004-03-10 Thread Ronald Wildenberg
snip

 
 public static LoginLog[] readLog()throws FileNotFoundException
 {
   Vector log = new Vector();
 
   try {
 FileReader inFile = new FileReader( /var/log/GFWlogin.log );
 BufferedReader bfFile = new BufferedReader( inFile );
   while ( bfFile.ready() ) {
 LoginLog logentry = getLogentry( bfFile );
 log.add( logentry );
   }
 bfFile.close();
} catch ( IOException e ) {} ;
return (LoginLog[])log.toArray( new LoginLog[log.size()] );
 }
 


Why not simply use:

   String line = null;
   while ((line = bfFile.readLine()) != null) {
  LoginLog logEntry = getLogEntry(line); // Create log entry from the
line just read.
  log.add(logEntry);
   }

There is no need to use 'bfFile.ready()'. This method only checks
whether the call to a read method may block, which is not a problem
at all.


Regards,
Ronald.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Tomcat 4.1 hangs on File Reading

2004-03-10 Thread Shapira, Yoav

Hi,

Why not simply use:

   String line = null;
   while ((line = bfFile.readLine()) != null) {
  LoginLog logEntry = getLogEntry(line); // Create log entry from
the
line just read.
  log.add(logEntry);
   }

There is no need to use 'bfFile.ready()'. This method only checks
whether the call to a read method may block, which is not a problem
at all.

I couldn't have said it any better -- good advice ;)

One thing you could have done (or still can do if you haven't changed
the code by now) is observe your program with a profiler, or even step
through it with a debugger, to see it never getting out if the
while(ready) loop.

Yoav Shapira



This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Tomcat 4.1 hangs on File Reading (Getting OT)

2004-03-10 Thread Ralph Einfeldt
Although I think that the solution is correct, (I have given 
the same advice) I think that the original solution should 
work (according to the apidoc):

From BuffereReader.ready():
Tell whether this stream is ready to be read. A buffered 
character stream is ready if the buffer is not empty, or 
if the underlying character stream is ready. 

From InputStreamReader.ready():

Tell whether this stream is ready to be read. An 
InputStreamReader is ready if its input buffer is not 
empty, or if bytes are available to be read from the 
underlying byte stream.

From this I would expect that ready() returns false at 
the end of the file.

 -Original Message-
 From: Shapira, Yoav [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, March 10, 2004 3:15 PM
 To: Tomcat Users List
 Subject: RE: Tomcat 4.1 hangs on File Reading
 
 
 
 Hi,
 
 Why not simply use:
 
String line = null;
while ((line = bfFile.readLine()) != null) {
   LoginLog logEntry = getLogEntry(line); // Create log entry from
 the
 line just read.
   log.add(logEntry);
}
 
 There is no need to use 'bfFile.ready()'. This method only checks
 whether the call to a read method may block, which is not a problem
 at all.
 
 I couldn't have said it any better -- good advice ;)
 
 One thing you could have done (or still can do if you haven't changed
 the code by now) is observe your program with a profiler, or even step
 through it with a debugger, to see it never getting out if the
 while(ready) loop.
 
 Yoav Shapira
 
 
 
 This e-mail, including any attachments, is a confidential 
 business communication, and may contain information that is 
 confidential, proprietary and/or privileged.  This e-mail is 
 intended only for the individual(s) to whom it is addressed, 
 and may not be saved, copied, printed, disclosed or used by 
 anyone else.  If you are not the(an) intended recipient, 
 please immediately delete this e-mail from your computer 
 system and notify the sender.  Thank you.
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Tomcat 4.1 hangs on File Reading

2004-03-10 Thread Adam Buglass
I'm still checking through so I can't say for sure,
but it looks certain enough that Ronald was correct,
although Peter's comment about using too many while
loops also improved performance.

I'm afraid I largely taught myself Java, coming from
a C / C++ background and misunderstood the method summary
for read().

Thanks for the help, and I'll take Yoav's tip on board too.

Adam.


On Wed, 2004-03-10 at 14:14, Shapira, Yoav wrote:
 Hi,
 
 Why not simply use:
 
String line = null;
while ((line = bfFile.readLine()) != null) {
   LoginLog logEntry = getLogEntry(line); // Create log entry from
 the
 line just read.
   log.add(logEntry);
}
 
 There is no need to use 'bfFile.ready()'. This method only checks
 whether the call to a read method may block, which is not a problem
 at all.
 
 I couldn't have said it any better -- good advice ;)
 
 One thing you could have done (or still can do if you haven't changed
 the code by now) is observe your program with a profiler, or even step
 through it with a debugger, to see it never getting out if the
 while(ready) loop.
 
 Yoav Shapira
 
 
 

 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Tomcat 4.1 hangs on File Reading (Getting OT)

2004-03-10 Thread Adam Buglass
On Wed, 2004-03-10 at 14:24, Ralph Einfeldt wrote:
 Although I think that the solution is correct, (I have given 
 the same advice) I think that the original solution should 
 work (according to the apidoc):
 
 From BuffereReader.ready():
 Tell whether this stream is ready to be read. A buffered 
 character stream is ready if the buffer is not empty, or 
 if the underlying character stream is ready. 
 
 From InputStreamReader.ready():
 
 Tell whether this stream is ready to be read. An 
 InputStreamReader is ready if its input buffer is not 
 empty, or if bytes are available to be read from the 
 underlying byte stream.
 
 From this I would expect that ready() returns false at 
 the end of the file.
 

That was also my (mis-) understanding but from the performance
of my program and the comments on people here I think I got the
wrong end of the stick somewhere.

I usually use Sun's class summaries and they're generally pretty
good.

I used it as I would have used while(inFile) in C,
where inFile is the name of the input stream.



  -Original Message-
  From: Shapira, Yoav [mailto:[EMAIL PROTECTED]
  Sent: Wednesday, March 10, 2004 3:15 PM
  To: Tomcat Users List
  Subject: RE: Tomcat 4.1 hangs on File Reading
  
  
  
  Hi,
  
  Why not simply use:
  
 String line = null;
 while ((line = bfFile.readLine()) != null) {
LoginLog logEntry = getLogEntry(line); // Create log entry from
  the
  line just read.
log.add(logEntry);
 }
  
  There is no need to use 'bfFile.ready()'. This method only checks
  whether the call to a read method may block, which is not a problem
  at all.
  
  I couldn't have said it any better -- good advice ;)
  
  One thing you could have done (or still can do if you haven't changed
  the code by now) is observe your program with a profiler, or even step
  through it with a debugger, to see it never getting out if the
  while(ready) loop.
  
  Yoav Shapira
  
  
  
  This e-mail, including any attachments, is a confidential 
  business communication, and may contain information that is 
  confidential, proprietary and/or privileged.  This e-mail is 
  intended only for the individual(s) to whom it is addressed, 
  and may not be saved, copied, printed, disclosed or used by 
  anyone else.  If you are not the(an) intended recipient, 
  please immediately delete this e-mail from your computer 
  system and notify the sender.  Thank you.
  
  
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  
  
  
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
-- 

Adam Buglass,  
The Golden Freeway,
Department of Child Health,
University of Newcastle-upon-Tyne.
Royal Victoria Infirmary.

(0191) 2023062

Democracy is two wolves and a lamb voting on what to have for lunch.
Liberty is a well-armed lamb contesting the vote. 
~Benjamin Franklin, 1759


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]