Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - Slow down in Java printing

 
Thread Tools Search this Thread
Old 03-08-2005, 08:46 PM   #1
Default Slow down in Java printing


I'm trying to print a job of around 20 MB. I'm breaking to 300 jobs
with 13 around 12-13 pages per job.(It's my customer's requirement). It

prints first 150 jobs fine after that I see a dramatic slow down. I'm
posting the print function below. Please suggest how I can improve this

and increase the speed


Thanks alot
PI


Code:


public int print(Graphics g, PageFormat pf, int PageIndex) throws
PrinterException
{
if (PageIndex != rememberedPageIndex) { // this can be called multiple
times for one page
rememberedPageIndex = PageIndex;
try {
getOnePage gop = new getOnePage(FileName, currPage);
currPage++;
OnePage = gop.PageString;
if (OnePage == "") {
return Printable.NO_SUCH_PAGE;


}


if(OnePage.charAt(0)=='\u001B'*){
return Printable.NO_SUCH_PAGE;

}
}


catch ( Exception e ) {
System.out.println("Unable to get page: " + e);


}


BeginDisp = 0;

int f = 20;
int done = 0;
double iw = pf.getImageableWidth();
while (done == 0) {
g.setFont(new Font("Monospaced", Font.BOLD, f));
FontMetrics fm = g.getFontMetrics();
if (fm.stringWidth(s) < iw) {
fnt = new Font("monospaced",Font.BOLD, f);
done = 1;
break;


}


f--;
if (f < 2){ // should not happen
done = 1;

}
}


LineHeight = (int) pf.getImageableHeight();
LineHeight = LineHeight / 66;


} else {
BeginDisp = 0;
}


g.setColor(Color.black);
g.setFont(fnt);
FontMetrics fm = g.getFontMetrics();
int centerAmtX = (int) ((pf.getImageableWidth() - fm.stringWidth(s)) /
2);
int x = (int) pf.getImageableX();
int y = (int) pf.getImageableY();
int pageBreak = (int) (y + pf.getImageableHeight());
int LineCount = 0;
while ((y + LineHeight) < pageBreak) {
LineCount++;
y += LineHeight;
if (OnePage.indexOf("\r",BeginDis*p) < 0) { // last line does not have
a
cr/lf
String LastLine = OnePage.substring(BeginDisp,On*ePage.length() - 1);
//
drop last character: page break
g.drawString(LastLine, (int) x + centerAmtX, (int) y);
break;

}


String line =
OnePage.substring(BeginDisp,On*ePage.indexOf("\r", BeginDisp))*;
g.drawString(line, (int) x + centerAmtX, (int) y);
BeginDisp = OnePage.indexOf("\r",BeginDisp*) + 2;
if (BeginDisp >= OnePage.length()) {
break;

}


LineHeight = " + LineHeight + " pageBreak = " + pageBreak);

}


return Printable.PAGE_EXISTS;



PseudoIntellectual
  Reply With Quote
Old 03-09-2005, 10:37 AM   #2
Thomas Weidenfeller
 
Posts: n/a
Default Re: Slow down in Java printing
PseudoIntellectual wrote:
> prints first 150 jobs fine after that I see a dramatic slow down. I'm
> posting the print function below. Please suggest how I can improve this


Use a profiler to measure(!) what is going on where.

/Thomas

--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq


Thomas Weidenfeller
  Reply With Quote
Old 03-11-2005, 09:51 AM   #3
jAnO!
 
Posts: n/a
Default Re: Slow down in Java printing

"PseudoIntellectual" <> wrote in message
news: oups.com...
I'm trying to print a job of around 20 MB. I'm breaking to 300 jobs
with 13 around 12-13 pages per job.(It's my customer's requirement). It

prints first 150 jobs fine after that I see a dramatic slow down. I'm
posting the print function below. Please suggest how I can improve this

and increase the speed


<Snip>
<sidenote>
If I had to maintain this code, I would hunt you down and kill you.
</sidenote>

Decrease in performance after an amount of time indicates to me that you
have a memory problem.
Try profiling your app. and see what is causing the problem, the processor
is probably GC ing.

hth,

jAnO!




jAnO!
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute an external software from VHDL? And how to interface VHDL with JAVA? becool_nikks Software 0 03-06-2009 07:08 PM
Live projects on C, C++, Java, .NET for final year students sheetal7853@gmail.com Software 0 10-05-2008 04:20 AM
Java Beginners Still Bill Software 3 02-19-2008 10:13 AM
Control Printing and Require Authentication for printing with using Java transformer Software 0 07-02-2007 04:33 AM
Re: Word Perfect 11 slow to print Linker3000 A+ Certification 1 07-12-2005 12:39 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46