import java.awt.image.BufferedImage;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import redis.clients.jedis.JedisCluster;
/**
* 激活用户
*
* @author skyler
* @time 2016-05-23
*/
@RestController
@RequestMapping("version{vv:\\d+}/user")
@Validated
public class UserController {
private static Logger log = LoggerFactory.getLogger(UserController.class);
@Resource
private ThreadPoolTaskExecutor taskExecutor;
@RequestMapping("/send_msg")
public ResponseJson sendMsg(long id) throws InterruptedException, ExecutionException {
//FutureTask<String> futureTask = new FutureTask<>(new MyCallable(200));
System.out.println(taskExecutor.getActiveCount());
taskExecutor.submit(new MyCallable(10));
Future<Object> f = taskExecutor.submit(new MyCallable(5));
System.out.println(f.get());
//taskExecutor.shutdown();
return new ResponseJson();
}
class MyCallable implements Callable<Object> {
private int id;
public MyCallable(int id) {
this.id = id;
}
@Override
public String call() throws Exception {
System.out.println("call()方法被调用!" + Thread.currentThread().getName());
// Thread.sleep(200);
List<Integer> list = new ArrayList<Integer>(10);
List<MessageInfo> msgList = new ArrayList<MessageInfo>();
// for (Integer i : list) {
// 1.组装短信对象
Message info = new Message("******", "您的验证码是:"
+ RandomStringUtils.random(6, true, true));
Message info2 = new Message("*******", "您的验证码是:
+ RandomStringUtils.rand
利用spring线程池ThreadPoolTaskExecutor发送手机短信
最新推荐文章于 2024-05-15 14:03:39 发布