UploadUtils.java 1022 字节
package com.framework.util;

import java.io.File;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.commons.lang3.StringUtils;

public class UploadUtils {

	private static Timer timer = new Timer(true);

	public static void uploadFile(String newFilePath) {
		if (StringUtils.isNotEmpty(newFilePath)) {
			String newPath = PropertiesLoader.get("UPLOAD_PATH") + newFilePath;

			File newFile = new File(newPath);
			// 判断是图片
			if (FileUtils.isImageFile(newPath)) {
				genImage(newFile);
			}
		}
	}

	private static void genImage(File ori) {
		try {
			timer.schedule(new ImageProcessTask(ori), 1000);
		} catch (IllegalStateException e) {
			synchronized (timer) {
				timer = new Timer(true);
			}
			timer.schedule(new ImageProcessTask(ori), 1000);
		}
	}
}

class ImageProcessTask extends TimerTask {

	private File ori;

	public ImageProcessTask(File ori) {
		this.ori = ori;
	}

	public void run() {
		ImageMagickUtils.resize(ori);
	}

}