爲了使用 redis 的分佈式可重入鎖, 決定引入 redissonjava
<dependency> <groupId>org.redisson</groupId> <artifactId>redisson</artifactId> <version>3.4.4</version> </dependency>
Config config = new Config(); config.setUseLinuxNativeEpoll(true); config.useClusterServers().addNodeAddress("redis://127.0.0.1:6379"); RedissonClient redissonClient = Redisson.create(config); RLock testLock = redissonClient.getLock("TEST_KEY"); testLock.lock(); testLock.lock();
java.lang.ClassNotFoundException: io.netty.channel.epoll.EpollEventLoopGroup
在 github 搜到 issues: https://github.com/redisson/r... git
根據提示引入指定包後出現新問題github
<dependency> <groupId>io.netty</groupId> <artifactId>netty-transport-native-epoll</artifactId> <version>4.0.40.Final</version> </dependency>
Caused by: java.lang.IllegalStateException: Only supported on Linux at io.netty.channel.epoll.Native.loadNativeLibrary(Native.java:267) at io.netty.channel.epoll.Native.<clinit>(Native.java:64)
又嘗試引入 netty-all 仍是同樣的錯redis
<!-- https://mvnrepository.com/artifact/io.netty/netty-all --> <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.5.Final</version> </dependency>
凝視代碼時發現了這句:config.setUseLinuxNativeEpoll(true);
好像跟錯誤有關, 嘗試着去除 netty 全部依賴後運行, 問題解決分佈式
不要太相信官方的示例代碼直接 copy , 要搞懂每句代碼的含義。oop