JasperReport大小限制
有没有办法设置JasperReport的大小限制? 我们刚看了一下WebSphere 6.1 Heapdump,有人试图创建一个报告,堆中有1.5GB的内存。 它让我们的Websphere服务器瘫痪了。 谢谢,T
我不熟悉JasperReports,但您可以包装I / O流以确保读/写的数据量不超过定义的限制。
OutputStream示例:
public class LimitedSizeOutputStream extends OutputStream { private final OutputStream delegate; private final long limit; private long written = 0L; /** * Creates a stream wrapper that will throw an IOException if the write * limit is exceeded. * * @param delegate * the underlying stream * @param limit * the maximum number of bytes this stream will accept */ public LimitedSizeOutputStream(OutputStream delegate, long limit) { this.delegate = delegate; this.limit = limit; } private void checkLimit(long byteCount) throws IOException { if (byteCount + written > limit) { throw new IOException("Exceeded stream size limit"); } written += byteCount; } @Override public void write(int b) throws IOException { checkLimit(1); delegate.write(b); } @Override public void write(byte[] b) throws IOException { checkLimit(b.length); delegate.write(b); } @Override public void write(byte[] b, int off, int len) throws IOException { checkLimit(len); delegate.write(b, off, len); } @Override public void close() throws IOException { delegate.close(); } }
包装InputStream同样容易。
JasperReports现在有“报告管理员”,限制报告输出的大小。 例如,您可以设置这些配置参数:
net.sf.jasperreports.governor.max.pages.enabled=[true|false]
net.sf.jasperreports.governor.max.pages=[integer]
有关详细信息,请参阅JasperReports论坛上的此post 。
您是否尝试限制从数据库返回的记录集中的行?