1.简单线程锁,一个一个访问


import com.zhl.framework.web.message.SimpleMessage;
import com.zhl.scheduling.service.ProgrammeService;
import com.zhl.scheduling.service.SchedulingDispatchMediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

@Service
public class SchedulingDispatchMediaServiceImpl implements SchedulingDispatchMediaService {
private final ReentrantLock lock = new ReentrantLock();

@Override
@Transactional
public SimpleMessage autoDispatchMedia(Map map) {
lock.lock();
try {
//需要执行的代码
return '调用自己的service层'(map);
} catch (Exception e) {
e.printStackTrace();
return SimpleMessage.fail("失败!");
} finally {
lock.unlock();
}
}
}

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。