简体   繁体   English

是否可以从两个不同的Servlet同时访问同一个DB?

[英]Is it possible to access concurrently to the same DB from two different Servlets?

I'm developing a web application, based on a DB. 我正在开发一个基于数据库的Web应用程序。 In my application, I access to this one from two different Servlets, and it's possible these accesses are concurrently. 在我的应用程序中,我从两个不同的Servlet访问这个,并且这些访问可能是同时进行的。

I need to know if it is permitted, and if not, how can I do it? 我需要知道是否允许,如果没有,我该怎么办? Is there some trick to perform queries in a thread-safe way? 是否有一些技巧以线程安全的方式执行查询?

It is possible and how to handle will be database responsibility based on DB settings (isolation level settings). 有可能并且如何处理将基于数据库设置(隔离级别设置)的数据库责任。

Here are the isolation levels in SQL Server and these may vary based on DB. 以下是SQL Server中的隔离级别,这些级别可能因DB而异。

1.Read uncommitted (the lowest level where transactions are isolated only enough to ensure that physically corrupt data is not read)

2.Read committed (Database Engine default level)

3.Repeatable read

4.Serializable (the highest level, where transactions are completely isolated from one another)

One of the primary design requirements for databases is concurrent access. 数据库的主要设计要求之一是并发访问。 Fact is, you are most probably already doing it in any one of your servlets since they can serve several requests in parallel, usng multiple db connections. 事实上,您很可能已经在任何一个 servlet中执行它,因为它们可以并行处理多个请求,使用多个数据库连接。 Using two connections from one app is (almost) exactly the same thing as using two connections from two apps. 使用来自一个应用程序的两个连接(几乎)与使用来自两个应用程序的两个连接完全相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 两个不同Servlet中的资源相同 - Same resource in two different servlets 如何在Java中同时访问同一对象的两种不同方法? - How to access two different methods of the same object concurrently in Java? 是否可以从两个不同的Java应用程序访问同一Ehcache对象? - Is it possible to access the same Ehcache object from two different java applications? 如何将相同的参数从一个JSP传递到两个servlet? 然后将servlet中的不同参数传递给相同的JSP? - how to pass the same parameter from one JSP to two servlets? Then pass the different parameters from servlet to the same JSP? 是否可以在不同的servlet,相同的WAR中使用不同的Spring Security AuthenticationProvider? - Is it possible to use a different Spring Security AuthenticationProvider in different servlets, same WAR? 并发运行时,多个Java线程访问同一数据库记录 - Multiple Java Threads access the same DB record when run concurrently 将两个不同的servlet映射到相同的URL模式 - Having two different servlets mapped on the same URL pattern 如何同时工作具有相同优先级的两个不同线程? - How to work concurrently two different threads which have the same priority? 可以使用两个线程访问LinkedList中同一对象的不同属性吗? - Possible to access to different attributes of the same object in a LinkedList using two Threads? 同步对两个或多个Servlet中的一个文件的访问 - Synchronizing access to one file from two or more Servlets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM