Tomcat中的JNDI配置(JNDI configuration in Tomcat)
我正在尝试在Web应用程序中设置JNDI查找以在Tomcat 7中进行部署。我在
jndi.properties
文件中指定了以下属性:java.naming.factory.initial = org.jnp.interfaces.NamingContextFactory,java.naming.factory.url.pkgs = org.jboss.naming:org.jnp.interfaces,java.naming.provider.url = localhost:1199
但是,当我得到初始上下文,并检查其属性,它显示
java.naming.factory.initial
更改为org.apache.naming.java.JavaURLContextFactory
和所有其他属性保持与jndi.properties
文件相同。我不明白为什么这单个属性获取更改? 我如何防止这种情况,并强制tomcat使用我指定的属性?I am trying to set up JNDI lookup in web application to be deployed in Tomcat 7. I have specified following properties in
jndi.properties
file:java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces, java.naming.provider.url=localhost:1199
But when i get initial context and inspecting its attributes it reveals that
java.naming.factory.initial
changes toorg.apache.naming.java.JavaURLContextFactory
and all other properties remains same as in thejndi.properties
file.I dont understand why this single property gets changes ? How can i prevent this and force tomcat to use property i have specified ?
原文:https://stackoverflow.com/questions/17104686
最满意答案
我不认为你可以使用锁定功能来做同样的事情,因为你会试图从内部屈服。 话虽如此,这在任何一种语言中看起来都是一种危险的方法,因为它意味着锁可以保持任意时间(例如,如果一个线程调用
Enumerate()
但不会一直枚举所产生的IEnumerable<_>
,那么锁将继续保持)。反转逻辑可能更有意义,提供了一个
iter
方法:let iter f = if synchronize then lock locker (fun () -> Seq.iter f dict) else Seq.iter f dict
这将迭代置于您的控制之下,确保序列完全迭代(假设
f
不会被阻止,这在任何情况下都是必要的假设),并且此后立即释放锁。编辑
以下是可以永久保存锁的代码示例。
let cached = enumerate() |> Seq.cache let firstFive = Seq.take 5 cached |> Seq.toList
我们已经锁定了开始列举前5项。 然而,我们没有继续完成其余的顺序,所以锁定不会被释放(也许我们会根据用户的反馈或其他事情来列举其余的方式,在这种情况下锁定会最终被释放) 。
在大多数情况下,正确编写的代码将确保它处理原始枚举器,但是一般情况下无法保证。 因此,你的序列表达式应该被设计为健壮的,只能被部分枚举。 如果你打算要求你的调用者一次枚举所有的集合,那么迫使他们通过你的函数来应用到每个元素要比返回他们可以随意列举的序列要好。
I don't think that you'll be able to do the same thing with the lock function, since you would be trying to yield from within it. Having said that, this looks like a dangerous approach in either language, since it means that the lock can be held for an arbitrary amount of time (e.g. if one thread calls
Enumerate()
but doesn't enumerate all the way through the resultingIEnumerable<_>
, then the lock will continue to be held).It may make more sense to invert the logic, providing an
iter
method along the lines of:let iter f = if synchronize then lock locker (fun () -> Seq.iter f dict) else Seq.iter f dict
This brings the iteration back under your control, ensuring that the sequence is fully iterated (assuming that
f
doesn't block, which seems like a necessary assumption in any case) and that the lock is released immediately thereafter.EDIT
Here's an example of code that could hold the lock forever.
let cached = enumerate() |> Seq.cache let firstFive = Seq.take 5 cached |> Seq.toList
We've taken the lock in order to start enumerating through the first 5 items. However, we haven't continued through the rest of the sequence, so the lock won't be released (maybe we would enumerate the rest of the way later based on user feedback or something, in which case the lock would finally be released).
In most cases, correctly written code will ensure that it disposes of the original enumerator, but there's no way to guarantee that in general. Therefore, your sequence expressions should be designed to be robust to only being enumerated part way. If you intend to require your callers to enumerate the collection all at once, then forcing them to pass you the function to apply to each element is better than returning a sequence which they can enumerate as they please.
相关问答
更多-
实现线程安全的数组(Implementing thread-safe arrays)[2024-01-14]
最好的方法是使用一些快速的读写器锁 。 您对只读访问执行共享锁定,对可写访问执行独占锁定 - 这种方式只能同时执行只读访问。 在用户模式的Win32 API中,Vista和更高版本中提供了Slim Reader / Writer(SRW)锁 。 在Vista之前,你必须自己实现读写器锁定功能,这是非常简单的任务。 您可以使用一个关键部分,一个事件和一个枚举/整型值来完成此操作。 虽然好的实现需要更多的努力 - 我会使用本地(堆栈分配)结构的手工链接列表来实现公平的等待队列。 The best way is ... -
非阻塞线程安全堆栈(Non-blocking thread-safe stack)[2023-10-25]
竞争条件是一个线程可以评估old_head->next ,就在调用unique_ptr的析构函数时(或之后)删除节点old_head指向的那个。 The race condition is that one thread could evaluate old_head->next, just when (or after) your unique_ptr's destructor is called that deletes the node old_head points to. -
锁定函数是否可以用于实现线程安全枚举?(Can the lock function be used to implement thread-safe enumeration?)[2023-06-12]
我不认为你可以使用锁定功能来做同样的事情,因为你会试图从内部屈服。 话虽如此,这在任何一种语言中看起来都是一种危险的方法,因为它意味着锁可以保持任意时间(例如,如果一个线程调用Enumerate()但不会一直枚举所产生的IEnumerable<_> ,那么锁将继续保持)。 反转逻辑可能更有意义,提供了一个iter方法: let iter f = if synchronize then lock locker (fun () -> Seq.iter f dict) else Seq.i ... -
我最终采用这种方法解决了这个问题: Read-Copy-Update 。 它似乎工作得很好 - 读取性能比基于锁定的方法快50倍(但这并不令人惊讶。) I ended up taking this approach to the problem: Read-Copy-Update. It seems to work quite well -- the read performance is 50x faster than the lock-based approach (but that's hardly ...
-
在处理集合时如何实现线程安全缓存机制?(How to implement a thread-safe cache mechanism when working with collections?)[2022-12-20]
是的,为了高效地实现缓存,它需要一个快速查找机制,所以List是开箱即用的错误数据结构。 Dictionary 是缓存的理想数据结构,因为它提供了一种替换方法: var value = instance.GetValueExpensive(key); 有: var value = instance.GetValueCached(key); 通过在字典中使用缓存值并使用字典来完成查找的繁重工作。 来电者并不聪明。 但是,如果调用者可以从多个线程进行调用,那么.NET4提供了 ... -
首先,你是正确的,博客中的代码有可能超出数组的末尾。 限制检查仅在获取互斥锁后完成时才有效。 这是我写这个函数的方法: bool func(char ctr) { bool result; /* lock the mutex here */ if (count >= sizeof(arr)) { result = FAILURE; } else { arr[count] = ctr; count++; ...
-
这段代码是否线程安全?(Is this code thread-safe?)[2021-12-11]
没有足够的代码来打电话。 但是,如果你没有序列化文件的写访问权,那么没有什么好事发生。 如果第一个线程仍然忙于写入文件,则分配该属性的第二个线程将抛出IOException异常。 像这样的细粒度锁定通常是一个问题。 客户端代码可能正在忙于更改该类的多个属性。 如果发生异常,您将得到部分更新,从而生成包含无效的序列化状态的文件,并且在读取时可能会造成麻烦。 你需要类似BeginUpdate(),EndUpdate()对的东西。 There's not enough code to make the call. ... -
您基本上有一个Read-Modify-Write操作。 如果你想确保事情变得混乱,那么最好是介绍读和写之间的延迟。 def inc(self): v = self.c time.sleep(random.random()) # Should probably limit it to a few hundred ms self.c = v + 1 def dec(self): v = self.c time.sleep(random.random()) # Shoul ...
-
请记住,如果你在GetEnumerator方法中取出一个锁,你可能会持有很长时间的锁,在此期间没有人能够将对象添加到你的集合中: foreach (var o in myCollection) { // Do something that takes 10 minutes } 您还需要考虑如果同时发生多次迭代会发生什么。 这意味着某种MRSW锁定(多个读取器单个写入器),您可能必须自己实现。 听起来你真正需要做的是迭代集合的快照: foreach (var o in myCollection.To ...
-
线程安全属性(Thread-Safe Properties)[2022-07-22]
这听起来像你想要的是一个与本地状态一起工作的Parallel.ForEach()的重载 。 在localInit委托中,您将创建一个新的ReportTotals实例,在localFinally您可以在锁定下将本地ReportTotals的值添加到全局ReportTotals中。 This sounds like what you want is an overload of Parallel.ForEach() that works with local state. In the localInit de ...