Thread View: borland.public.jbuilder.java.language
7 messages
7 total messages
Started by scott
Fri, 27 May 2005 20:11
StackOverflowException with a logging class
Author: scott
Date: Fri, 27 May 2005 20:11
Date: Fri, 27 May 2005 20:11
219 lines
7441 bytes
7441 bytes
I've written a class to handle logging (haven't learned log4j yet).
It's designed so that any number of implementations can be added to the logger.
The Logger class� constructor looks like this:
public Logger(LoggerImpl impl) {
startDate = new Date();
lastMsg = new String();
requirements = new Hashtable();
attributes = new Hashtable();
attributeValues = new Hashtable();
traces = new Hashtable();
otherObjects = new Hashtable();
implementations = new Vector();
addImplementation(impl);
}
I�ve written one implementation for system.out and one that writes to a text file.
The system.out code is below (text file just passes in a different out variable).
I think this is a basic Bridge (or maybe Strategy?) pattern.
The application that uses it scans about 4500 Caliber requirements, outputting lots
of details along the way. As it does, it calls methods that look like this:
public void reportRequirement(Requirement req, String msg){
if (!requirements.containsKey(req.getID())){
requirements.put(req.getID(), req);
}
Iterator iter = implementations.iterator();
while (iter.hasNext()){
LoggerImpl impl = (LoggerImpl)iter.next();
impl.reportRequirement(req, msg);
}
}
I'm getting Stack Overflow errors when I run the program and want to eliminate
the logger as the cause.
Does anyone see any problem with this code? Maybe the hashtables get too big?
Thanks
package com.rps.caliber.loggers;
import com.starbase.caliber.*;
import com.starbase.caliber.attribute.Attribute;
import com.starbase.caliber.attribute.AttributeValue;
import com.starbase.caliber.server.RemoteServerException;
import java.io.PrintStream;
import java.io.FileOutputStream;
/**
* <p>Title: PrintStreamLoggerImpl</p>
*
* <p>Description: An implementation for Logger that writes to any PrintStream.
* By default, System.out is used.</p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: Research Pharmaceutical Services</p>
*
* @author Scott Powell
* @version 1.0
*/
public class PrintStreamLoggerImpl extends LoggerImpl {
PrintStream out = System.out;
public PrintStreamLoggerImpl() {
super();
}
/**
* Set the PrintStream to be used by this implementation.
* @param stream, the PrintStream to use.
* @return void
*/
public void setOutputStream(PrintStream stream){
this.out = stream;
}
/**
* Returns the print stream used by this implementation.
* @return the PrintStream
*/
public PrintStream getPrintStream(){
return this.out;
}
/**
* Prints a summary of logged activities
* @return void
*/
public void printSummary() {
out.println(logger.getSummary());
}
/**
* reportAttribute
*
* @param attr Attribute
* @param msg String
*/
public void reportAttribute(Attribute attr, String msg) {
out.println ("Attribute: " + attr.getName().toString() + ", " + msg +
". (" + this.logger.getNumAttributes() + ") so far.");
}
/**
* reportAttributeValue
*
* @param value AttributeValue
* @param msg String
*/
public void reportAttributeValue(AttributeValue value, String msg) {
try {
out.println("AttributeValue: " + value.getAttribute().getName() + ", " + msg +
". (" + this.logger.getNumAttributeValues() + ") so far.");
} catch (RemoteServerException ex) {
logger.reportException(ex, "The AttributeValue could not be accessed.");
}
}
/**
* reportException
*
* @param e RemoteServerException
*/
public void reportException(RemoteServerException e) {
out.println("***** Start RemoteServerException *****");
out.println("The following error has occurred: " + e.getMessage());
e.printStackTrace(out);
out.println(this.logger.getNumExceptions() + " exceptions so far.");
out.println("***** End RemoteServerException *****");
}
/**
* reportException
*
* @param e Exception
* @param msg String
*/
public void reportException(Exception e, String msg) {
out.println("***** Start Exception *****");
out.println("The following error has occurred: " + e.getMessage());
e.printStackTrace(out);
reportMessage(msg);
out.println(this.logger.getNumExceptions() + " exceptions so far.");
out.println("***** End Exception *****");
}
/**
* reportException
*
* @param e Exception
*/
public void reportException(Exception e) {
out.println("***** Start Exception *****");
out.println("The following error has occurred: " + e.getMessage());
e.printStackTrace(out);
out.println(this.logger.getNumExceptions() + " exceptions so far.");
out.println("***** End Exception *****");
}
/**
* reportMessage
*
* @param msg String The message
*/
public void reportMessage(String msg) {
out.println(msg);
}
/**
* reportObject
*
* @param obj CaliberObject
* @param msg String
*/
public void reportObject(CaliberObject obj, String msg) {
out.println("Caliber Object: " + obj.getClass().toString() + ", " + msg +
". (" + this.logger.getNumOtherObjects() + ") so far.");
}
/**
* reportRequirement
*
* @param req Requirement that's reported
* @param msg String that is the message
*/
public void reportRequirement(Requirement req, String msg) {
String reqMsg = logger.getRequirementMsg(req);
out.println ("Requirement: " + reqMsg + ", " + msg +
". (" + this.logger.getNumRequirements() + ") so far.");
out.flush();
}
/**
* reportTrace
*
* @param trace Trace that's reported
* @param msg String that is the message
*/
public void reportTrace(Trace trace, String msg) {
String trcMsg = logger.getTraceMsg(trace);
out.println("Trace: " + trcMsg + ", " + msg +
". (" + this.logger.getNumTraces() + ") so far.");
}
}
Re: StackOverflowException with a logging class
Author: Alexey N. Solofnenko
Date: Fri, 27 May 2005 20:21
Date: Fri, 27 May 2005 20:21
8 lines
1273 bytes
1273 bytes
Please try running the program in debugger or add dummy print statements
through out your code to see where stack overflow happens.
- Alexey.
--
Alexey N. Solofnenko {trelony at gmail.com}
home: http://trelony.cjb.net/
Re: StackOverflowException with a logging class
Author: scott
Date: Fri, 27 May 2005 20:30
Date: Fri, 27 May 2005 20:30
37 lines
1930 bytes
1930 bytes
Alexei,
Thanks for the suggestion.
I've commented out all of the logger calls and the app runs
without getting the Stack Overflow.
So let's say the problem is in the logger.
There are 4000+ requirements and probably 32,000 total calls to
the logger methods. It could take a lot of "step over" clicks
to wait for the logger to blow up.
Dummy print statements seem problematic since that's basically
what the logger does: writes to System.out.
Can you suggest anything else?
Could you see the hashtables growing large enough that they're
causing the problem?
I think stack overflows are typically recursion related, but I don't really see any chance for that in this code. Maybe I'm missing something.
Scott
"Alexey N. Solofnenko" <trelony@mail.ru> wrote:
>Please try running the program in debugger or add dummy print statements
>through out your code to see where stack overflow happens.
>
>- Alexey.
>
>--
>Alexey N. Solofnenko {trelony at gmail.com}
>home: http://trelony.cjb.net/
Re: StackOverflowException with a logging class
Author: Alexey N. Solofnenko
Date: Fri, 27 May 2005 20:40
Date: Fri, 27 May 2005 20:40
49 lines
2476 bytes
2476 bytes
Dummy prints usually help. Another suggestion would be disabling
(commenting out) some functionality until the program starts working.
- Alexey.
scott wrote:
> Alexei,
>
> Thanks for the suggestion.
>
> I've commented out all of the logger calls and the app runs
> without getting the Stack Overflow.
>
> So let's say the problem is in the logger.
>
> There are 4000+ requirements and probably 32,000 total calls to
> the logger methods. It could take a lot of "step over" clicks
> to wait for the logger to blow up.
>
> Dummy print statements seem problematic since that's basically
> what the logger does: writes to System.out.
>
> Can you suggest anything else?
>
> Could you see the hashtables growing large enough that they're
> causing the problem?
>
> I think stack overflows are typically recursion related, but I don't really see any chance for that in this code. Maybe I'm missing something.
>
> Scott
>
>
>
> "Alexey N. Solofnenko" <trelony@mail.ru> wrote:
>
>>Please try running the program in debugger or add dummy print statements
>>through out your code to see where stack overflow happens.
>>
>>- Alexey.
>>
>>--
>>Alexey N. Solofnenko {trelony at gmail.com}
>>home: http://trelony.cjb.net/
>
>
--
Alexey N. Solofnenko {trelony at gmail.com}
home: http://trelony.cjb.net/
Re: StackOverflowException with a logging class
Author: scott
Date: Fri, 27 May 2005 20:48
Date: Fri, 27 May 2005 20:48
57 lines
2543 bytes
2543 bytes
Alexey,
How do I do a dummy print?
Scott
"Alexey N. Solofnenko" <trelony@mail.ru> wrote:
>Dummy prints usually help. Another suggestion would be disabling
>(commenting out) some functionality until the program starts working.
>
>- Alexey.
>
>scott wrote:
>> Alexei,
>>
>> Thanks for the suggestion.
>>
>> I've commented out all of the logger calls and the app runs
>> without getting the Stack Overflow.
>>
>> So let's say the problem is in the logger.
>>
>> There are 4000+ requirements and probably 32,000 total calls to
>> the logger methods. It could take a lot of "step over" clicks
>> to wait for the logger to blow up.
>>
>> Dummy print statements seem problematic since that's basically
>> what the logger does: writes to System.out.
>>
>> Can you suggest anything else?
>>
>> Could you see the hashtables growing large enough that they're
>> causing the problem?
>>
>> I think stack overflows are typically recursion related, but I don't really see any chance for that in this code. Maybe I'm missing something.
>>
>> Scott
>>
>>
>>
>> "Alexey N. Solofnenko" <trelony@mail.ru> wrote:
>>
>>>Please try running the program in debugger or add dummy print statements
>>>through out your code to see where stack overflow happens.
>>>
>>>- Alexey.
>>>
>>>--
>>>Alexey N. Solofnenko {trelony at gmail.com}
>>>home: http://trelony.cjb.net/
>>
>>
>
>--
>Alexey N. Solofnenko {trelony at gmail.com}
>home: http://trelony.cjb.net/
Re: StackOverflowException with a logging class
Author: Alexey N. Solofnenko
Date: Fri, 27 May 2005 20:58
Date: Fri, 27 May 2005 20:58
22 lines
1738 bytes
1738 bytes
System.out.println("1"); // all println() should print unique strings
//do something
System.out.println("2");
//do something else
System.out.println("2.1.3");
The goal is to get some number is printed continuously. If it does not
happen, look at the last printed number, guess what was executed after
that and add more println() calls.
- Alexey.
scott wrote:
> Alexey,
>
> How do I do a dummy print?
>
> Scott
>
--
Alexey N. Solofnenko {trelony at gmail.com}
home: http://trelony.cjb.net/
Re: StackOverflowException with a logging class
Author: Arthur Ore
Date: Sat, 28 May 2005 15:42
Date: Sat, 28 May 2005 15:42
60 lines
3110 bytes
3110 bytes
Hi Scott,
If you've got 32000 lines of code, should be able to determine which line is
causing you problem in 15 or less debugging sessions, by using a kind of
binary chop with break points. (As Math.pow(2,15)=32768)
Set a break point roughly halfway through your code and debug. If you don't
get a stack overflow before the break point, then you know the problem is in
the second half of your code. You can then set another break point about 3/4
of the way though you code and narrow it down. If you get the stack overflow
in the first part of your program, leave your original breakpoint in place,
but add another breakpoint 1/4 through your code and re-debug.
I use this approach in conjunction with Alexey's method of displaying unique
messages to quickly track down the problem areas of code.
Arth
"scott" <spowell@rpsweb.com> wrote in message
news:42978357@newsgroups.borland.com...
>
> Alexei,
>
> Thanks for the suggestion.
>
> I've commented out all of the logger calls and the app runs
> without getting the Stack Overflow.
>
> So let's say the problem is in the logger.
>
> There are 4000+ requirements and probably 32,000 total calls to
> the logger methods. It could take a lot of "step over" clicks
> to wait for the logger to blow up.
>
> Dummy print statements seem problematic since that's basically
> what the logger does: writes to System.out.
>
> Can you suggest anything else?
>
> Could you see the hashtables growing large enough that they're
> causing the problem?
>
> I think stack overflows are typically recursion related, but I don't
> really see any chance for that in this code. Maybe I'm missing something.
>
> Scott
>
>
>
> "Alexey N. Solofnenko" <trelony@mail.ru> wrote:
>>Please try running the program in debugger or add dummy print statements
>>through out your code to see where stack overflow happens.
>>
>>- Alexey.
>>
>>--
>>Alexey N. Solofnenko {trelony at gmail.com}
>>home: http://trelony.cjb.net/
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads