当我从jedis执行函数getResource
时,它崩溃了以下问题:
[17:04:58] [Paper Watchdog Thread / ERROR]:当前线程:服务器线程 [17:04:58] [Paper Watchdog Thread / ERROR]:PID:18 |暂停:false | Native:false |州:等待 [17:04:58] [Paper Watchdog Thread / ERROR]:线程在监视器上等待: [17:04:58] [Paper Watchdog Thread / ERROR]:已锁定:org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:499) [17:04:58] [Paper Watchdog Thread / ERROR]:Stack: [17:04:58] [Paper Watchdog Thread / ERROR]:sun.misc.Unsafe.park(Native Method) [17:04:58] [Paper Watchdog Thread / ERROR]:java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) [17:04:58] [Paper Watchdog Thread / ERROR]:java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject.await(AbstractQueuedSynchronizer.java:2039) [17:04:58] [Paper Watchdog Thread / ERROR]:org.apache.commons.pool2.impl.LinkedBlockingDeque.takeFirst(LinkedBlockingDeque.java:583) [17:04:58] [Paper Watchdog Thread / ERROR]:org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:442) [17:04:58] [Paper Watchdog Thread / ERROR]:org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) [17:04:58] [Paper Watchdog Thread / ERROR]:redis.clients.util.Pool.getResource(Pool.java:49) [17:04:58] [Paper Watchdog Thread / ERROR]:redis.clients.jedis.JedisPool.getResource(JedisPool.java:226) [17:04:58] [Paper Watchdog Thread / ERROR]:pl.imoobler.sectors.managers.RedisManager.updatePosition(RedisManager.java:44) [17:04:58] [Paper Watchdog Thread / ERROR]:pl.imoobler.sectors.utils.BungeeUtils.teleportServer(BungeeUtils.java:28) [17:04:58] [Paper Watchdog Thread / ERROR]:pl.imoobler.sectors.listeners.PlayerMoveListener.detectSectorSwap(PlayerMoveListener.java:88) [17:04:58] [Paper Watchdog Thread / ERROR]:com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor6.execute(Unknown Source) [17:04:58] [Paper Watchdog Thread / ERROR]:org.bukkit.plugin.EventExecutor $ 1.execute(EventExecutor.java:44) [17:04:58] [Paper Watchdog Thread / ERROR]:co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:78) [17:04:58] [Paper Watchdog Thread / ERROR]:org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) [17:04:58] [Paper Watchdog Thread / ERROR]:org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:514) [17:04:58] [Paper Watchdog Thread / ERROR]:org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:499) [17:04:58] [Paper Watchdog Thread / ERROR]:net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:649) [17:04:58] [Paper Watchdog Thread / ERROR]:net.minecraft.server.v1_12_R1.PacketPlayInFlying.a(SourceFile:126) [17:04:58] [Paper Watchdog Thread / ERROR]:net.minecraft.server.v1_12_R1.PacketPlayInFlying $ PacketPlayInPosition.a(SourceFile:57) [17:04:58] [Paper Watchdog Thread / ERROR]:net.minecraft.server.v1_12_R1.PlayerConnectionUtils.lambda $ ensureMainThread $ 0(PlayerConnectionUtils.java:14) [17:04:58] [Paper Watchdog Thread / ERROR]:net.minecraft.server.v1_12_R1.PlayerConnectionUtils $$ Lambda $ 199 / 2109184961.run(Unknown Source) [17:04:58] [Paper Watchdog Thread / ERROR]:java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511) [17:04:58] [Paper Watchdog Thread / ERROR]:java.util.concurrent.FutureTask.run(FutureTask.java:266) [17:04:58] [Paper Watchdog Thread / ERROR]:net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [17:04:58] [Paper Watchdog Thread / ERROR]:net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:842) [17:04:58] [Paper Watchdog Thread / ERROR]:net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:423) [17:04:58] [Paper Watchdog Thread / ERROR]:net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:766) [17:04:58] [Paper Watchdog Thread / ERROR]:net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:664) [17:04:58] [Paper Watchdog Thread / ERROR]:java.lang.Thread.run(Thread.java:748) [17:04:58] [Paper Watchdog Thread / ERROR]:------------------------------
我的代码:
package pl.imoobler.sectors.managers;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.bukkit.Bukkit;
import pl.imoobler.sectors.SectorsPlugin;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPubSub;
import redis.clients.jedis.exceptions.JedisConnectionException;
import java.util.UUID;
public class RedisManager {
SectorsPlugin plugin;
JedisPool pool;
Gson gson = new Gson();
public RedisManager(SectorsPlugin plugin, String redisHost) {
this.plugin = plugin;
pool = new JedisPool(redisHost);
}
public void subscribe(final JedisPubSub pubSub, final String... channels) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
public void run() {
Jedis jedis = pool.getResource();
try {
jedis.select(0);
jedis.subscribe(pubSub, channels);
} catch (JedisConnectionException ex) {
pool.returnBrokenResource(jedis);
} finally {
pool.returnResource(jedis);
}
}
});
}
public void updatePosition(UUID uuid, String position, String target) {
Jedis subscriber = null;
try {
subscriber = pool.getResource();
subscriber.set(("sectors:" + "positions" + ":" + uuid.toString()), position);
JsonObject object = new JsonObject();
object.addProperty("position_player_uuid", uuid.toString());
object.addProperty("position_player_target", target);
subscriber.publish("NewPlayerLocationChannel", gson.toJson(object));
}catch(JedisConnectionException ex) {
pool.returnBrokenResource(subscriber);
} finally {
pool.returnResource(subscriber);
}
}
public String getPosition(UUID uuid) {
Jedis subscriber = pool.getResource();
if(subscriber.exists(("sectors:" + "positions" + ":" + uuid.toString()))) {
return subscriber.get(("sectors:" + "positions" + ":" + uuid.toString()));
}
return null;
}
}
答案 0 :(得分:0)
您是否达到了JedisPool尺寸?默认的JedisPool大小非常小。