|
@@ -18,6 +18,7 @@ import javax.annotation.Resource;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Executors;
|
|
|
|
+import java.util.concurrent.LinkedBlockingQueue;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Created by zhengmin on 2017/2/24.
|
|
* Created by zhengmin on 2017/2/24.
|
|
@@ -47,16 +48,23 @@ public class ImageApi {
|
|
@Resource
|
|
@Resource
|
|
ImageServerConfig imageServerConfig;
|
|
ImageServerConfig imageServerConfig;
|
|
|
|
|
|
- private ExecutorService executor = Executors.newFixedThreadPool(10);
|
|
|
|
|
|
+ private ExecutorService executor = Executors.newFixedThreadPool(1);
|
|
|
|
|
|
private HashSet<String> papers = new HashSet<String>();
|
|
private HashSet<String> papers = new HashSet<String>();
|
|
|
|
|
|
|
|
+ LinkedBlockingQueue<RotateTask> queue = new LinkedBlockingQueue<>();
|
|
|
|
+
|
|
@RequestMapping(value = "{paperId}/rotate", method = RequestMethod.GET)
|
|
@RequestMapping(value = "{paperId}/rotate", method = RequestMethod.GET)
|
|
public ResponseEntity rotate(@PathVariable Long paperId, @RequestParam int degree) {
|
|
public ResponseEntity rotate(@PathVariable Long paperId, @RequestParam int degree) {
|
|
Paper paper = paperRepo.findOne(paperId);
|
|
Paper paper = paperRepo.findOne(paperId);
|
|
- if (!papers.contains(paper.getExamNumber())) {
|
|
|
|
- executor.submit(new RotateTask(paper, degree, paperRepo, systemConfig, papers, imageConfig, studentRepo, ossUtil, aliYunOssConfig, imageServerConfig));
|
|
|
|
- papers.add(paper.getExamNumber());
|
|
|
|
|
|
+// if (!papers.contains(paper.getExamNumber())) {
|
|
|
|
+// executor.submit(new RotateTask(paper, degree, paperRepo, systemConfig, papers, imageConfig, studentRepo, ossUtil, aliYunOssConfig, imageServerConfig));
|
|
|
|
+// papers.add(paper.getExamNumber());
|
|
|
|
+// }
|
|
|
|
+ RotateTask rotateTask = new RotateTask(paper, degree, paperRepo, systemConfig, papers, imageConfig, studentRepo, ossUtil, aliYunOssConfig, imageServerConfig);
|
|
|
|
+ queue.offer(rotateTask);
|
|
|
|
+ while (queue.size() > 0) {
|
|
|
|
+ executor.submit(queue.poll());
|
|
}
|
|
}
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
}
|
|
}
|