mirror of
https://github.com/dromara/tianai-captcha.git
synced 2026-05-07 06:04:34 +08:00
更改没图片时缓存报错的bug
This commit is contained in:
@@ -34,13 +34,28 @@ public class CacheSliderCaptchaTemplate implements SliderCaptchaTemplate {
|
||||
queue = new LinkedList<>();
|
||||
// 初始化一个队列扫描
|
||||
scheduledExecutor.scheduleAtFixedRate(() -> {
|
||||
while (pos.get() < this.size) {
|
||||
int count = pos.incrementAndGet();
|
||||
if (count > size) {
|
||||
return;
|
||||
try {
|
||||
while (pos.get() < this.size) {
|
||||
if (pos.get() >= size) {
|
||||
return;
|
||||
}
|
||||
SliderCaptchaInfo slideImageInfo = target.getSlideImageInfo();
|
||||
if (slideImageInfo != null) {
|
||||
queue.add(slideImageInfo);
|
||||
// 添加记录
|
||||
pos.incrementAndGet();
|
||||
}else {
|
||||
// 休眠500毫秒
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(500);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
SliderCaptchaInfo slideImageInfo = target.getSlideImageInfo();
|
||||
queue.add(slideImageInfo);
|
||||
} catch (Exception e) {
|
||||
// cache所有
|
||||
log.error("缓存队列扫描时出错, ex", e);
|
||||
}
|
||||
}, 0, 100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cloud.tianai.captcha.template.slider;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
@@ -21,6 +22,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
* @Date 2020/5/29 8:06
|
||||
* @Description 滑块验证码模板
|
||||
*/
|
||||
@Slf4j
|
||||
public class DefaultSliderCaptchaTemplate implements SliderCaptchaTemplate {
|
||||
|
||||
/**
|
||||
@@ -186,6 +188,11 @@ public class DefaultSliderCaptchaTemplate implements SliderCaptchaTemplate {
|
||||
|
||||
@SneakyThrows
|
||||
public SliderCaptchaInfo getSlideImageInfo(String targetFormatName, String matrixFormatName) {
|
||||
if (resourceImageFiles.isEmpty() || templateImageFiles.isEmpty()) {
|
||||
log.warn("滑块验证码生成失败, 资源或模板为空,不能进行生成, 资源文件列表长度: {}, 模板文件列表长度: {}",
|
||||
resourceImageFiles.size(), templateImageFiles.size());
|
||||
return null;
|
||||
}
|
||||
URL resourceImage = getRandomResourceImage();
|
||||
Map<String, URL> templateImages = getRandomTemplateImages();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user