Disruptor的开发应用

        工作时遇到更新大量数据问题简单应用了一下Disruptor。Disruptor被称为一个并发框架,但主要是一个数据队列,想要掌握它,应先学习线程容器:BlockingQueue等知识 ,并清晰的认识:多个生产者---队列---多个消费者的模式。
1导jar包
2 创建一个基本的包装类
`package vinux.web.openApi.controller;

import java.util.List;
import java.util.Map;

import vinux.service.dao.VinuxCenterMemberSellerMapper;
import vinux.service.entity.VinuxCenterMemberSeller;

public class Element {

private  VinuxCenterMemberSellerMapper sellerMapper;

private List<VinuxCenterMemberSeller> mdcList ;

private Integer type;

private Map<String, Object> params;


public VinuxCenterMemberSellerMapper getSellerMapper() {
    return sellerMapper;
}

public void setSellerMapper(VinuxCenterMemberSellerMapper sellerMapper) {
    this.sellerMapper = sellerMapper;
}

public List<VinuxCenterMemberSeller> getMdcList() {
    return mdcList;
}

public void setMdcList(List<VinuxCenterMemberSeller> mdcList) {
    this.mdcList = mdcList;
}

public Integer getType() {
    return type;
}

public void setType(Integer type) {
    this.type = type;
}

public Map<String, Object> getParams() {
    return params;
}

public void setParams(Map<String, Object> params) {
    this.params = params;
}

}
3这是一个添加到队列的类package vinux.web.openApi.controller;

import java.util.List;
import java.util.Map;

import vinux.service.dao.VinuxCenterMemberSellerMapper;
import vinux.service.entity.VinuxCenterMemberSeller;

public class Element {

private  VinuxCenterMemberSellerMapper sellerMapper;

private List<VinuxCenterMemberSeller> mdcList ;

private Integer type;

private Map<String, Object> params;


public VinuxCenterMemberSellerMapper getSellerMapper() {
    return sellerMapper;
}

public void setSellerMapper(VinuxCenterMemberSellerMapper sellerMapper) {
    this.sellerMapper = sellerMapper;
}

public List<VinuxCenterMemberSeller> getMdcList() {
    return mdcList;
}

public void setMdcList(List<VinuxCenterMemberSeller> mdcList) {
    this.mdcList = mdcList;
}

public Integer getType() {
    return type;
}

public void setType(Integer type) {
    this.type = type;
}

public Map<String, Object> getParams() {
    return params;
}

public void setParams(Map<String, Object> params) {
    this.params = params;
}

}
4package vinux.web.openApi.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import vinux.service.dao.VinuxCenterMemberSellerMapper;
import vinux.service.entity.VinuxCenterMemberSeller;

import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.WorkHandler;
/**
*
* updateProductWhereC_PRODUCT_COUNT\\
*
* dayStartTime
*
* dayEndTime
* */
public class Handler1 implements EventHandler, WorkHandler {

@Override
public void onEvent(Element event) throws Exception {
    try {
        SimpleDateFormat myFmt1=new SimpleDateFormat("yyyy-MM-dd"); 

        Map<String, Object> params = new HashMap<String, Object>(); 

        VinuxCenterMemberSellerMapper sellerMapper = event.getSellerMapper();

        List<VinuxCenterMemberSeller> mdcList = event.getMdcList();

        for (VinuxCenterMemberSeller vinuxCenterMemberSeller : mdcList) {

            Date calculateDate = vinuxCenterMemberSeller.getCalculateDate();

            String format = myFmt1.format(calculateDate);
            params.put("dayStartTime", format+" 00:00:00");
            params.put("dayEndTime", format+" 23:59:59");
            params.put("id", vinuxCenterMemberSeller.getUserId());
            sellerMapper.updateProductWhereC_PRODUCT_COUNT(params);
        }
    } catch (Exception e) {

        e.printStackTrace();

    }


}   

@Override
public void onEvent(Element event, long arg1, boolean arg2) throws Exception {
    this.onEvent(event);  
}

}
这里可以看成一个Service
5disruptor的配置和调用
Map

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值