/** * Creates a new instance. * * @param corePoolSize the maximum number of active threads * @param maxChannelMemorySize the maximum total size of the queued events per channel. * Specify {@code 0} to disable. * @param maxTotalMemorySize the maximum total size of the queued events for this pool * Specify {@code 0} to disable. * @param keepAliveTime the amount of time for an inactive thread to shut itself down * @param unit the {@link TimeUnit} of {@code keepAliveTime} * @param threadFactory the {@link ThreadFactory} of this pool */ public MemoryAwareThreadPoolExecutor( int corePoolSize, long maxChannelMemorySize, long maxTotalMemorySize, long keepAliveTime, TimeUnit unit, ThreadFactory threadFactory) { this( corePoolSize, maxChannelMemorySize, maxTotalMemorySize, keepAliveTime, unit, new DefaultObjectSizeEstimator(), threadFactory); }
public int estimateSize(Object o) { if (o == null) { return 8; } int answer = 8 + estimateSize(o.getClass(), null); if (o instanceof EstimatableObjectWrapper) { answer += estimateSize(((EstimatableObjectWrapper) o).unwrap()); } else if (o instanceof MessageEvent) { answer += estimateSize(((MessageEvent) o).getMessage()); } else if (o instanceof ChannelBuffer) { answer += ((ChannelBuffer) o).capacity(); } else if (o instanceof byte[]) { answer += ((byte[]) o).length; } else if (o instanceof ByteBuffer) { answer += ((ByteBuffer) o).remaining(); } else if (o instanceof CharSequence) { answer += ((CharSequence) o).length() << 1; } else if (o instanceof Iterable<?>) { for (Object m : (Iterable<?>) o) { answer += estimateSize(m); } } return align(answer); }
@Override public int estimateSize(Object o) { int size; if (o instanceof ChannelBuffer) { size = ((ChannelBuffer) o).readableBytes(); } else { size = super.estimateSize(o); } return size; } }
answer += estimateSize(f.getType(), visitedClasses); answer = align(answer);
public int estimateSize(Object o) { if (o == null) { return 8; } int answer = 8 + estimateSize(o.getClass(), null); if (o instanceof EstimatableObjectWrapper) { answer += estimateSize(((EstimatableObjectWrapper) o).unwrap()); } else if (o instanceof MessageEvent) { answer += estimateSize(((MessageEvent) o).getMessage()); } else if (o instanceof ChannelBuffer) { answer += ((ChannelBuffer) o).capacity(); } else if (o instanceof byte[]) { answer += ((byte[]) o).length; } else if (o instanceof ByteBuffer) { answer += ((ByteBuffer) o).remaining(); } else if (o instanceof CharSequence) { answer += ((CharSequence) o).length() << 1; } else if (o instanceof Iterable<?>) { for (Object m : (Iterable<?>) o) { answer += estimateSize(m); } } return align(answer); }
answer += estimateSize(f.getType(), visitedClasses); answer = align(answer);