|
@@ -1,16 +1,16 @@ |
|
|
package com.telpo.iotgateway.listener; |
|
|
package com.telpo.iotgateway.listener; |
|
|
|
|
|
|
|
|
import com.google.common.base.Stopwatch; |
|
|
import com.google.common.base.Stopwatch; |
|
|
|
|
|
import com.google.common.util.concurrent.ThreadFactoryBuilder; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.lang3.concurrent.BasicThreadFactory; |
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
import javax.jms.Message; |
|
|
import javax.jms.Message; |
|
|
import javax.jms.MessageListener; |
|
|
import javax.jms.MessageListener; |
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
import java.util.concurrent.ScheduledExecutorService; |
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
import javax.validation.constraints.Positive; |
|
|
|
|
|
import java.util.concurrent.*; |
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -36,13 +36,15 @@ public class IotMessageListener implements MessageListener { |
|
|
public void run() { |
|
|
public void run() { |
|
|
// task to run goes here |
|
|
// task to run goes here |
|
|
count.getAndSet(0); |
|
|
count.getAndSet(0); |
|
|
System.out.println("Hello, stranger"); |
|
|
|
|
|
|
|
|
log.warn("约1分钟处理 {} 个请求",count); |
|
|
|
|
|
//System.out.println("Hello, stranger"); |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// ScheduledExecutorService:是从Java SE5的java.util.concurrent里, |
|
|
// ScheduledExecutorService:是从Java SE5的java.util.concurrent里, |
|
|
// 做为并发工具类被引进的,这是最理想的定时任务实现方式。 |
|
|
// 做为并发工具类被引进的,这是最理想的定时任务实现方式。 |
|
|
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); |
|
|
|
|
|
|
|
|
ScheduledExecutorService service = new ScheduledThreadPoolExecutor(1, |
|
|
|
|
|
new BasicThreadFactory.Builder().namingPattern("count-schedule-pool-%d").daemon(true).build()); |
|
|
// 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间 |
|
|
// 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间 |
|
|
// 10:秒 5:秒 |
|
|
// 10:秒 5:秒 |
|
|
// 第一次执行的时间为10秒,然后每隔五秒执行一次 |
|
|
// 第一次执行的时间为10秒,然后每隔五秒执行一次 |
|
|