Преглед на файлове

计数线程处理调整

master
林万龙 преди 3 години
родител
ревизия
e43bb19863
променени са 1 файла, в които са добавени 8 реда и са изтрити 6 реда
  1. +8
    -6
      src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java

+ 8
- 6
src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java Целия файл

@@ -1,16 +1,16 @@
package com.telpo.iotgateway.listener;

import com.google.common.base.Stopwatch;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Message;
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;

/**
@@ -36,13 +36,15 @@ public class IotMessageListener implements MessageListener {
public void run() {
// task to run goes here
count.getAndSet(0);
System.out.println("Hello, stranger");
log.warn("约1分钟处理 {} 个请求",count);
//System.out.println("Hello, stranger");
}
};

// 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秒,然后每隔五秒执行一次


Loading…
Отказ
Запис