在 jndi.properties 中声明变量

Declare variable in jndi.properties

我想知道是否可以在 jndi.properties 中声明自定义 int 或整数。

我正在做一个 JMS 程序。我想 "give" 轻松地为程序提供一个整数。

我试图自己找,但找不到任何有趣的东西。

那么我是否真的可以将 jndi 格式化为仅按严格规则使用。

我想在 jndi.propreties 做什么:

#number of threads accepted
int.maxThreads = 3 

#queue.[jndiName] = [physicalName]
queue.MyQueue = MyQueue2

然后在 java 中:

int maxThreadsTemp = (int) ctx.lookup("maxThreads");

我尝试过但失败了。我得到正常:"javax.naming.NameNotFoundException: maxThreads"

那么我是说错了还是根本不可能这样做? 提前致谢。

*编辑:我使用 ActiveMQ,对于 JNDI,我使用这个 url 来做到这一点:http://activemq.apache.org/jndi-support.html

我找到了答案:我所做的是忘记了方法 lookup(...)

ctx = new InitialContext(...);
int maxThreadsTemp = (int) ctx.lookup("maxThreads");

相反,我使用了哈希表(简单得多):

ctx = new InitialContext(...);
Hashtable<?, ?> environment =  ctx.getEnvironment();
            String nbrThread = (String)  environment.get("maxThreads");

在 jndi.properties 中:maxThreads = 5(感谢@Claus Ibsen)