JMagic 切割图片时,使用多线程异步大幅提高性能
由于使用 jQuery blueimp 的上传组件及 yoxView 显示组件,图片上传后自动切割成8个不同规格的图片,如果采用单线程处理 10x3M 的文件需要 2分20秒,如果加入了多线程异步(并做了单线程优先生成即时显示的缩略图)需要 53秒,完成任务是一样的,而对于前端的用户体验差别明显。
...
if(profile != null){
final ThumbnailSize[] sizes = profile.getSizes();
final String finalNewFilePath =newFilePath;
final boolean keepRatio = true;
if(sizes.length>0){
// 特殊处理,先切割前端即时显示的缩略图
if(IS_PREGENERATE_THUMBNAIL){
final int width_ = PREGENERATE_THUMBNAIL_SIZE.getWidth();
final int height_ = PREGENERATE_THUMBNAIL_SIZE.getHeight();
String thumbnailPath = PhotoBean.getPhotoThnumailPath(photo.getVolumeId(), photo.getId(),suffix, width_, height_);
final String thumbnailPath_ = FileUtil.getFilePathUploadFileUri(thumbnailPath);
ImageUtil.resize(finalNewFilePath, thumbnailPath_, width_, height_, keepRatio);
}
// 处理余下的尺寸
for(int i=0; i<sizes.length; i++){
// 略过之前即时处理过的尺寸
if(IS_PREGENERATE_THUMBNAIL &&(sizes[i].getWidth()==PREGENERATE_THUMBNAIL_SIZE.getWidth())
&&(sizes[i].getHeight()==PREGENERATE_THUMBNAIL_SIZE.getHeight())){
continue;
}
final int width_ = sizes[i].getWidth();
final int height_ = sizes[i].getHeight();
String thumbnailPath = PhotoBean.getPhotoThnumailPath(photo.getVolumeId(), photo.getId(),suffix, width_, height_);
final String thumbnailPath_ = FileUtil.getFilePathUploadFileUri(thumbnailPath);
Runnable syncResizeImage= new Runnable() {
public void run() {
ImageUtil.resize(finalNewFilePath, thumbnailPath_, width_, height_, keepRatio);
if (width_ >= 600)//只有当待切割的图片宽大于或等于600时才打印上水印
ImageWatermarksUtil.pressImage(watermarkerImgPath, thumbnailPath_, 20, 20);
System.out.println("newFilePath=="+finalNewFilePath +",--"+thumbnailPath_+","+width_+","+height_+","+keepRatio);
}
};
this.execute(syncResizeImage);
}
}
}
...
...
private void execute(Runnable runnable){
if(this.executor==null){
logger.debug("New fixed Thread Pool size is 10.");
this.executor =Executors.newFixedThreadPool(10);
}
executor.execute(runnable);
}
...
分享到:
相关推荐
or1200 openrisc-arch-1.0-rev0.pdf
cacti-plugin-arch-2.0.tar.gz
Processor Arch-Sequential
Next Generation On Demand (NGOD) Asset Architecture Comcast-SP-NGOD-ASSET-ARCH-I03-100731 Issued July 31, 2010
UPnP arch Device architecture v1.1.pdf 2008年的1.1版本。
基于android8.1源码平台中生成的jar,亲测可用!!!!
藏经阁-Distributed-Frontend-Arch--Ahmad Amireh.pdf
Next Generation On Demand (NGOD) Overall Architecture Comcast-SP-NGOD-GEN-ARCH-I03-100731 Issued July 31, 2010
Arch-JL-10-4in1.pdf
变系数ARCH-M模型的ARCH效应检验,熊强, 李元,本文考虑变系数ARCH-M模型, 构造了非参数部分和参数部分的截面似然估计. 基于估计的渐近性质, 构造了Wald检验统计量来检验模型是否具�
arch-for-sync-groupware-tr1999-425
python库。 资源全名:arch-4.8.0-cp27-cp27m-win32.whl
NULL 博文链接:https://cnmqw.iteye.com/blog/1243596
资源来自pypi官网。 资源全名:arch-4.17-cp39-cp39-manylinux1_x86_64.whl
python库,解压后可用。 资源全名:arch-4.11-cp35-cp35m-win32.whl
NULL 博文链接:https://cnmqw.iteye.com/blog/1115403
NULL 博文链接:https://cnmqw.iteye.com/blog/1056307
UPnP-arch-DeviceArchitecture-v2.0 最新的UPNP协议规范
资源来自pypi官网。 资源全名:arch-4.9.1-cp36-cp36m-macosx_10_6_intel.whl
下午1_Intel_Yang, Elton_MeeGo-Arch-Update-Final.pdf