java-简单线程锁

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();
}
}
}

猜你喜欢

转载自www.cnblogs.com/bt2882/p/10871256.html