appleappleapple / distributelearning Goto Github PK
View Code? Open in Web Editor NEW分布式学习
分布式学习
请使用utf-8编码
`long lockExpireTime = System.currentTimeMillis() + lockExpires + 1;// 锁超时时间
//假设System.currentTimeMillis() =0,lockExpires=1,lockExpireTime则=2,并且此时有三个jvm实例中的线程j1,j2,j3同时执行到这里,
String stringOfLockExpireTime = String.valueOf(lockExpireTime);
System.out.println("test4");
if (jedis.setnx(lockKey, stringOfLockExpireTime) == 1) { // 获取到锁
System.out.println("test5");
//成功获取到锁, 设置相关标识
locked = true;
setExclusiveOwnerThread(Thread.currentThread());
return true;
}
System.out.println("test6");
String value = jedis.get(lockKey);
if (value != null && isTimeExpired(value)) { // lock is expired
System.out.println("test7");
// 假设多个线程(非单jvm)同时走到这里
String oldValue = jedis.getSet(lockKey, stringOfLockExpireTime); //原子操作
// 但是走到这里时每个线程拿到的oldValue肯定不可能一样(因为getset是原子性的)
// 加入拿到的oldValue依然是expired的,那么就说明拿到锁了
//**假设此时System.currentTimeMillis()=3并且此时j1线执行getSet操作得到旧值o1,o1<3成功拿到锁,然//后j1执行getSet操作设置新值,并获取到旧值为stringOfLockExpireTime=2 <3也拿到锁 **
System.out.println("test8");
if (oldValue != null && isTimeExpired(oldValue)) {
System.out.println("test9");
//成功获取到锁, 设置相关标识
locked = true;
setExclusiveOwnerThread(Thread.currentThread());
return true;
}
} `
https://blog.csdn.net/hry2015/article/details/74937375?locationNum=6&fps=1个人觉得使用rua脚本是否好一点
请使用utf-8编码
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.