DeviceThreadPoolConfig.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.xy.config;
  2. import com.dtp.core.support.DynamicTp;
  3. import com.xy.utils.ThreadPoolUtils;
  4. import org.springframework.context.annotation.Bean;
  5. import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
  6. import org.springframework.stereotype.Component;
  7. @Component
  8. public class DeviceThreadPoolConfig {
  9. public static final String DEVICE_COMMON_POLL = "deviceCommonPoll";
  10. public static final String DEVICE_DATA_POLL = "deviceDataPoll";
  11. public static final String DEVICE_NETWORK_POLL = "deviceNetWorkPoll";
  12. public static final String ALIPAY_DEVICE_DETAIL = "alipayDeviceDetail";
  13. public static final String ALI_DEVICE_ACTIVE = "aliDeviceActive";
  14. /**
  15. * 公用线程池
  16. */
  17. @DynamicTp
  18. @Bean(DEVICE_COMMON_POLL)
  19. public ThreadPoolTaskExecutor deviceCommonPoll() {
  20. int coreSize = 5;
  21. return ThreadPoolUtils.newPoll()
  22. .name(DEVICE_COMMON_POLL)
  23. .coreSize(coreSize)
  24. .maxSize(coreSize * 2)
  25. .keepAlive(60)
  26. .queueSize(coreSize * 10)
  27. .builder();
  28. }
  29. /**
  30. * 统计mqtt消费线程池
  31. */
  32. @DynamicTp
  33. @Bean(DEVICE_DATA_POLL)
  34. public ThreadPoolTaskExecutor deviceDataPoll() {
  35. int coreSize = 5;
  36. return ThreadPoolUtils.newPoll()
  37. .name(DEVICE_DATA_POLL)
  38. .coreSize(coreSize)
  39. .maxSize(coreSize * 10)
  40. .keepAlive(30)
  41. .queueSize(coreSize * 10)
  42. .builder();
  43. }
  44. /**
  45. * 上下线mqtt消费线程池
  46. */
  47. @DynamicTp
  48. @Bean(DEVICE_NETWORK_POLL)
  49. public ThreadPoolTaskExecutor deviceNetWorkPoll() {
  50. int coreSize = 5;
  51. return ThreadPoolUtils.newPoll()
  52. .name(DEVICE_NETWORK_POLL)
  53. .coreSize(coreSize)
  54. .maxSize(coreSize * 10)
  55. .keepAlive(30)
  56. .queueSize(coreSize * 10)
  57. .builder();
  58. }
  59. /**
  60. * 查询支付宝设备详情线程池
  61. */
  62. @DynamicTp
  63. @Bean(ALIPAY_DEVICE_DETAIL)
  64. public ThreadPoolTaskExecutor alipayDeviceDetail() {
  65. int coreSize = 5;
  66. return ThreadPoolUtils.newPoll()
  67. .name(ALIPAY_DEVICE_DETAIL)
  68. .coreSize(coreSize)
  69. .maxSize(coreSize * 10)
  70. .keepAlive(30)
  71. .queueSize(coreSize * 10)
  72. .builder();
  73. }
  74. /**
  75. * 支付宝设备激活线程池
  76. */
  77. @DynamicTp
  78. @Bean(ALI_DEVICE_ACTIVE)
  79. public ThreadPoolTaskExecutor aliDeviceActive() {
  80. int coreSize = 1;
  81. return ThreadPoolUtils.newPoll()
  82. .name(ALI_DEVICE_ACTIVE)
  83. .coreSize(coreSize)
  84. .maxSize(coreSize * 10)
  85. .keepAlive(30)
  86. .queueSize(coreSize)
  87. .builder();
  88. }
  89. }