[英]Declare variable in jndi.properties
I want to know if it is possible to declare à custom int or integer in jndi.properties. 我想知道是否可以在jndi.properties中声明àcustom int或integer。
I'm doing a JMS program. 我正在做一个JMS程序。 And I want to "give" easly an int to the program. 而且我想轻松地“赋予”该程序一个int。
I tried to find by myself, but I can't find anything interesting. 我试图独自寻找,但找不到任何有趣的东西。
So can I or is jndi really formated to be use only by strict rules. 我可以还是jndi可以格式化为只能由严格的规则使用?
What I want to do in jndi.propreties: 我想在jndi.propreties中做什么:
#number of threads accepted
int.maxThreads = 3
#queue.[jndiName] = [physicalName]
queue.MyQueue = MyQueue2
Then in java : 然后在java中:
int maxThreadsTemp = (int) ctx.lookup("maxThreads");
I tryed but failed. 我尝试了但是失败了。 I get the normal : "javax.naming.NameNotFoundException: maxThreads" 我得到正常的:“ javax.naming.NameNotFoundException:maxThreads”
So did I declared it wrong or is it just impossible to do so ? 那我是说错了还是做不到呢? Thanks in advance. 提前致谢。
*Edit : I use ActiveMQ and for JNDI I used this url to do it : http://activemq.apache.org/jndi-support.html *编辑:我使用ActiveMQ,对于JNDI,我使用此URL来完成: http : //activemq.apache.org/jndi-support.html
I found the answer : What I did was to forget the methode lookup(...) 我找到了答案:我所做的就是忘记了方法查询(...)
ctx = new InitialContext(...);
int maxThreadsTemp = (int) ctx.lookup("maxThreads");
Instead I used a hashtable (much simpler): 相反,我使用了一个哈希表(简单得多):
ctx = new InitialContext(...);
Hashtable<?, ?> environment = ctx.getEnvironment();
String nbrThread = (String) environment.get("maxThreads");
And in jndi.properties : maxThreads = 5
(thx to @Claus Ibsen) 并在jndi.properties中: maxThreads = 5
(@Claus Ibsen表示感谢)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.