RMI - 线程池子线程套接字权限问题

发布于 2024-11-05 13:20:42 字数 3466 浏览 3 评论 0原文

我有一个线程池,其计划线程访问 redis 池并用它执行一些查询。

我在创建 ThreadPool 的类中将 JedisPool 实例创建为静态实例。 我在构建每个任务时将 JedisPool 实例作为参数传递。我的构造函数将是 public TestTask(DataSource ds, JedisPool pool, int xx, int yy)。由于该任务还需要 mysql 连接,因此我传递了 mysql 连接池数据源的实例。所有这些文件都在“packagen”中。

我的 server.policy 文件位于“/home/raja/parent_to_package/”目录中,如下所示,

grant codeBase "file:/home/raja/parent_to_package/" {

permission java.security.AllPermission;

permission java.net.SocketPermission "*:*","connect,resolve";

};

grant codeBase "file:/home/raja/parent_to_package/packagen/" {

permission java.security.AllPermission;

permission java.net.SocketPermission "*:*","connect,resolve";

};

我从parent_to_package 目录运行程序,就像

java  -Djava.rmi.server.codebase=file:/home/raja/parent_to_package/interface.jar -Djava.rmi.server.hostname=192.168.0.1 -Djava.security.policy=/home/raja/parent_to_package/server.policy  -Xmx256m -Xms256m packagen.MainClass                                

我仍然从子线程中得到以下异常。

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
        at redis.clients.util.Pool.getResource(Pool.java:22)
        at packagen.TestTask.run(TestTask.java:172)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
        at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:573)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:570)
        at java.lang.Thread.run(Thread.java:619)


Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:6379 connect,resolve)
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
        at java.security.AccessController.checkPermission(AccessController.java:546)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
        at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
        at java.net.Socket.connect(Socket.java:513)
        at java.net.Socket.connect(Socket.java:469)
        at java.net.Socket.<init>(Socket.java:366)
        at java.net.Socket.<init>(Socket.java:180)
        at redis.clients.jedis.Connection.connect(Connection.java:105)
        at redis.clients.jedis.Jedis.connect(Jedis.java:1657)
        at redis.clients.jedis.JedisPool$JedisFactory.makeObject(JedisPool.java:63)
        at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:974)
        at redis.clients.util.Pool.getResource(Pool.java:20)
        ... 13 more

I've a Threadpool whose scheduled threads access the redis pool and perform some query with it.

I create the JedisPool instance as static in a class in which ThreadPool is created.
I pass the JedisPool instance as a parameter while constructing each task. My constructor will be public TestTask(DataSource ds, JedisPool pool, int xx, int yy). Since the task also requires a mysql connection I pass an instance of mysql connection pool's datasource. All these files are in a "packagen".

My server.policy file is in "/home/raja/parent_to_package/" directory and looks like this,

grant codeBase "file:/home/raja/parent_to_package/" {

permission java.security.AllPermission;

permission java.net.SocketPermission "*:*","connect,resolve";

};

grant codeBase "file:/home/raja/parent_to_package/packagen/" {

permission java.security.AllPermission;

permission java.net.SocketPermission "*:*","connect,resolve";

};

I run the program from parent_to_package directory like

java  -Djava.rmi.server.codebase=file:/home/raja/parent_to_package/interface.jar -Djava.rmi.server.hostname=192.168.0.1 -Djava.security.policy=/home/raja/parent_to_package/server.policy  -Xmx256m -Xms256m packagen.MainClass                                

Still I get the following exception from the child threads.

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
        at redis.clients.util.Pool.getResource(Pool.java:22)
        at packagen.TestTask.run(TestTask.java:172)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
        at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:573)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:570)
        at java.lang.Thread.run(Thread.java:619)


Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:6379 connect,resolve)
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
        at java.security.AccessController.checkPermission(AccessController.java:546)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
        at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)
        at java.net.Socket.connect(Socket.java:513)
        at java.net.Socket.connect(Socket.java:469)
        at java.net.Socket.<init>(Socket.java:366)
        at java.net.Socket.<init>(Socket.java:180)
        at redis.clients.jedis.Connection.connect(Connection.java:105)
        at redis.clients.jedis.Jedis.connect(Jedis.java:1657)
        at redis.clients.jedis.JedisPool$JedisFactory.makeObject(JedisPool.java:63)
        at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:974)
        at redis.clients.util.Pool.getResource(Pool.java:20)
        ... 13 more

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦浮鱼 2024-11-12 13:20:42

鉴于您使用的是 jar 文件,我认为您的 codeBase 规范不正确,并且我认为您的 SocketPermissions 也没有正确指定主机:端口。检查文档。

I don't think your codeBase specifications are correct given you are using a jar file,and I don't think your SocketPermissions are correctly specifying the host:port either. Check the documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文