首页 \ 问答 \ Tomcat中的JNDI配置(JNDI configuration in Tomcat)

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 to org.apache.naming.java.JavaURLContextFactory and all other properties remains same as in the jndi.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
更新时间:2022-02-09 16:02

最满意答案

我不认为你可以使用锁定功能来做同样的事情,因为你会试图从内部屈服。 话虽如此,这在任何一种语言中看起来都是一种危险的方法,因为它意味着锁可以保持任意时间(例如,如果一个线程调用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 resulting IEnumerable<_>, 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.

相关问答

更多
  • 最好的方法是使用一些快速的读写器锁 。 您对只读访问执行共享锁定,对可写访问执行独占锁定 - 这种方式只能同时执行只读访问。 在用户模式的Win32 API中,Vista和更高版本中提供了Slim Reader / Writer(SRW)锁 。 在Vista之前,你必须自己实现读写器锁定功能,这是非常简单的任务。 您可以使用一个关键部分,一个事件和一个枚举/整型值来完成此操作。 虽然好的实现需要更多的努力 - 我会使用本地(堆栈分配)结构的手工链接列表来实现公平的等待队列。 The best way is ...
  • 竞争条件是一个线程可以评估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.
  • 我不认为你可以使用锁定功能来做同样的事情,因为你会试图从内部屈服。 话虽如此,这在任何一种语言中看起来都是一种危险的方法,因为它意味着锁可以保持任意时间(例如,如果一个线程调用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 ...
  • 是的,为了高效地实现缓存,它需要一个快速查找机制,所以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++; ...
  • 没有足够的代码来打电话。 但是,如果你没有序列化文件的写访问权,那么没有什么好事发生。 如果第一个线程仍然忙于写入文件,则分配该属性的第二个线程将抛出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 ...
  • 这听起来像你想要的是一个与本地状态一起工作的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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)