@ -7,8 +7,6 @@ import com.kiisoo.ic.store.mapper.PrivilageCpUserStoreDOMapper;
import com.kiisoo.ic.wx.service.QWMailListManageService ;
import com.kiisoo.ic.wx.service.QWMailListManageService ;
import com.lmax.disruptor.* ;
import com.lmax.disruptor.* ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import me.chanjar.weixin.cp.bean.WxCpUserExternalContactInfo ;
import org.apache.commons.collections.CollectionUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
@ -32,10 +30,10 @@ public class CustomerSyncJob {
private CustomerService customerService ;
private CustomerService customerService ;
public void syncCustomer ( ) throws ExecutionException , InterruptedException {
public void syncCustomer ( ) throws ExecutionException , InterruptedException {
long beginTime = System . currentTimeMillis ( ) ;
long beginTime = System . currentTimeMillis ( ) ;
int BUFFER_SIZE = 1024 ;
int BUFFER_SIZE = 1024 * 1024 ;
int THREAD_NUMBERS = 4 ;
int THREAD_NUMBERS = 10 ;
/ *
/ *
* createSingleProducer 创 建 一 个 单 生 产 者 的 RingBuffer ,
* createSingleProducer 创 建 一 个 单 生 产 者 的 RingBuffer ,
* 第 一 个 参 数 叫 EventFactory , 从 名 字 上 理 解 就 是 “ 事 件 工 厂 ” , 其 实 它 的 职 责 就 是 产 生 数 据 填 充 RingBuffer 的 区 块 。
* 第 一 个 参 数 叫 EventFactory , 从 名 字 上 理 解 就 是 “ 事 件 工 厂 ” , 其 实 它 的 职 责 就 是 产 生 数 据 填 充 RingBuffer 的 区 块 。
@ -47,7 +45,7 @@ public class CustomerSyncJob {
public DTOMessage newInstance ( ) {
public DTOMessage newInstance ( ) {
return new DTOMessage ( ) ;
return new DTOMessage ( ) ;
}
}
} , BUFFER_SIZE , new YieldingWaitStrategy ( ) ) ;
} , BUFFER_SIZE , new YieldingWaitStrategy ( ) ) ;
//创建线程池
//创建线程池
ExecutorService executors = Executors . newFixedThreadPool ( THREAD_NUMBERS ) ;
ExecutorService executors = Executors . newFixedThreadPool ( THREAD_NUMBERS ) ;
//创建SequenceBarrier
//创建SequenceBarrier
@ -64,7 +62,7 @@ public class CustomerSyncJob {
executors . submit ( transProcessor ) ;
executors . submit ( transProcessor ) ;
//如果存大多个消费者 那重复执行上面3行代码 把TradeTransactionInDBHandler换成其它消费者类
//如果存大多个消费者 那重复执行上面3行代码 把TradeTransactionInDBHandler换成其它消费者类
Future < ? > future = executors . submit ( new Callable < Void > ( ) {
Future < ? > future = executors . submit ( new Callable < Void > ( ) {
@Override
@Override
public Void call ( ) throws Exception {
public Void call ( ) throws Exception {
List < PrivilageCpUserStoreDO > privilageCpUserStoreDOS = privilageCpUserStoreDOMapper . selectList ( null ) ;
List < PrivilageCpUserStoreDO > privilageCpUserStoreDOS = privilageCpUserStoreDOMapper . selectList ( null ) ;
@ -72,7 +70,7 @@ public class CustomerSyncJob {
for ( PrivilageCpUserStoreDO privilageCpUserStoreDO : privilageCpUserStoreDOS ) {
for ( PrivilageCpUserStoreDO privilageCpUserStoreDO : privilageCpUserStoreDOS ) {
String cpUserId = privilageCpUserStoreDOMapper . selectCpUserIdByStoreId ( privilageCpUserStoreDO . getStoreId ( ) ) ;
String cpUserId = privilageCpUserStoreDOMapper . selectCpUserIdByStoreId ( privilageCpUserStoreDO . getStoreId ( ) ) ;
seq = ringBuffer . next ( ) ; //占个坑 --ringBuffer一个可用区块
seq = ringBuffer . next ( ) ; //占个坑 --ringBuffer一个可用区块
//给这个区块放入 数据 如果此处不理解, 想想RingBuffer的结构图
//给这个区块放入 数据 如果此处不理解, 想想RingBuffer的结构图
ringBuffer . get ( seq ) . setCpUserId ( cpUserId ) ;
ringBuffer . get ( seq ) . setCpUserId ( cpUserId ) ;
@ -83,7 +81,7 @@ public class CustomerSyncJob {
// ringBuffer.get(seq).setCustomers(customers);
// ringBuffer.get(seq).setCustomers(customers);
ringBuffer . publish ( seq ) ; //发布这个区块的数据使handler(consumer)可见
ringBuffer . publish ( seq ) ; //发布这个区块的数据使handler(consumer)可见
}
}
return null ;
return null ;
}
}
} ) ;
} ) ;
@ -92,6 +90,6 @@ public class CustomerSyncJob {
transProcessor . halt ( ) ; //通知事件(或者说消息)处理器 可以结束了(并不是马上结束!!!)
transProcessor . halt ( ) ; //通知事件(或者说消息)处理器 可以结束了(并不是马上结束!!!)
executors . shutdown ( ) ; //终止线程
executors . shutdown ( ) ; //终止线程
System . out . println ( "总耗时:" + ( System . currentTimeMillis ( ) - beginTime ) ) ;
System . out . println ( "总耗时:" + ( System . currentTimeMillis ( ) - beginTime ) ) ;
}
}
}
}