久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <i id='Z6flf'><tr id='Z6flf'><dt id='Z6flf'><q id='Z6flf'><span id='Z6flf'><b id='Z6flf'><form id='Z6flf'><ins id='Z6flf'></ins><ul id='Z6flf'></ul><sub id='Z6flf'></sub></form><legend id='Z6flf'></legend><bdo id='Z6flf'><pre id='Z6flf'><center id='Z6flf'></center></pre></bdo></b><th id='Z6flf'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Z6flf'><tfoot id='Z6flf'></tfoot><dl id='Z6flf'><fieldset id='Z6flf'></fieldset></dl></div>
    1. <legend id='Z6flf'><style id='Z6flf'><dir id='Z6flf'><q id='Z6flf'></q></dir></style></legend>

      <small id='Z6flf'></small><noframes id='Z6flf'>

      • <bdo id='Z6flf'></bdo><ul id='Z6flf'></ul>
        <tfoot id='Z6flf'></tfoot>
      1. Spring/J2EE Apps 中的只讀和讀寫分離

        Segregating the read-only and read-write in Spring/J2EE Apps(Spring/J2EE Apps 中的只讀和讀寫分離)

          <tbody id='8bcKw'></tbody>
        • <bdo id='8bcKw'></bdo><ul id='8bcKw'></ul>
          <i id='8bcKw'><tr id='8bcKw'><dt id='8bcKw'><q id='8bcKw'><span id='8bcKw'><b id='8bcKw'><form id='8bcKw'><ins id='8bcKw'></ins><ul id='8bcKw'></ul><sub id='8bcKw'></sub></form><legend id='8bcKw'></legend><bdo id='8bcKw'><pre id='8bcKw'><center id='8bcKw'></center></pre></bdo></b><th id='8bcKw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8bcKw'><tfoot id='8bcKw'></tfoot><dl id='8bcKw'><fieldset id='8bcKw'></fieldset></dl></div>
            <tfoot id='8bcKw'></tfoot>

            <small id='8bcKw'></small><noframes id='8bcKw'>

                  <legend id='8bcKw'><style id='8bcKw'><dir id='8bcKw'><q id='8bcKw'></q></dir></style></legend>
                1. 本文介紹了Spring/J2EE Apps 中的只讀和讀寫分離的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我們在項目中使用 Spring、Spring-Data 和 JPA.

                  We using Spring, Spring-Data and JPA in our project.

                  對于生產服務器,我們希望設置數據庫集群,以便所有讀取查詢都指向一臺服務器,所有寫入查詢都指向另一臺服務器.

                  For production servers, we would like to setup database cluster such that all read queries are directed to one server and all write queries are directed to another server.

                  這顯然需要對 DAO 的構建方式進行一些更改.

                  This obviously will require some changes in the way the DAOs are built.

                  如果到目前為止,有人一直使用 Spring-Data/JPA 遵循食譜風格的 DAO 創建,其中 DAO 實現負責讀取和寫入,那么有誰知道如何實現這一點?需要在架構上進行什么樣的更改來隔離這兩種類型的調用?

                  Does anyone know how to achieve this if one has, so far, been following cook-book style DAO creations using Spring-Data/JPA where a DAO implementation is responsible for both reads and writes? What kind of changes in architecture will be needed to segregate the two types of calls?

                  推薦答案

                  在使用 MySQL 時,Java 開發人員通常使用 Connector/J 作為 JDBC 驅動程序.開發者通常使用Connector/J com.mysql.jdbc.Driver 類,通過諸如jdbc:mysql://host[:port]/database 的URL 來連接到 MySQL 數據庫.

                  When using MySQL, it is common for Java developers to use Connector/J as the JDBC driver. Developers typically use the Connector/J com.mysql.jdbc.Driver class, with a URL such as jdbc:mysql://host[:port]/database to connect to MySQL databases.

                  Connector/J 提供了另一個名為 ReplicationDriver 允許應用程序在多個 MySQL 主機之間進行負載平衡.使用 ReplicationDriver 時,JDBC URL 更改為 jdbc:mysql:replication://master-host[:master-port][,slave-1-host[:slave-1-port]][,slave-2-host[:slave-2-port]]/database.這允許應用程序連接到多個服務器之一,具體取決于在任何給定時間點可用的服務器.

                  Connector/J offers another driver called ReplicationDriver that allows an application to load-balance between multiple MySQL hosts. When using ReplicationDriver, the JDBC URL changes to jdbc:mysql:replication://master-host[:master-port][,slave-1-host[:slave-1-port]][,slave-2-host[:slave-2-port]]/database. This allows the application to connect to one of multiple servers depending on which one is available at any given point in time.

                  使用 ReplicationDriver 時,如果 JDBC 連接設置為 read-only,驅動程序會將 URL 中聲明的第一個主機視為 read-將 主機和所有其他主機寫入只讀 主機.開發人員可以通過如下構造他們的代碼在 Spring 應用程序中利用這一點:

                  When using the ReplicationDriver, if a JDBC connection is set to read-only, the driver treats the first host declared in the URL as a read-write host and all others as read-only hosts. Developers can take advantage of this in a Spring application by structuring their code as follows:

                  @Service
                  @Transactional(readOnly = true)
                  public class SomeServiceImpl implements SomeService {
                     public SomeDataType readSomething(...) { ... }
                  
                     @Transactional(readOnly = false)
                     public void writeSomething(...) { ... }
                  }
                  

                  這樣的代碼,每當readSomething方法被調用時,Spring事務管理代碼都會獲取一個JDBCConnection并調用setReadOnly(true)code> 在它上面,因為服務方法默認使用 @Transactional(readOnly = true) 注釋.這將使來自 readSomething 方法的所有數據庫查詢轉到非主 MySQL 主機之一,以循環方式進行負載平衡.同樣,每當writeSomething被調用時,Spring都會在底層的JDBCConnection上調用setReadOnly(false),強制數據庫查詢到master服務器.

                  With code like this, whenever the method readSomething is called, the Spring transaction management code will obtain a JDBC Connection and call setReadOnly(true) on it because the service methods are annotated with @Transactional(readOnly = true) by default. This will make all database queries from the readSomething method to go to one of the non-master MySQL hosts, load-balanced in a round-robin fashion. Similarly, whenever writeSomething is called, Spring will call setReadOnly(false) on the underlying JDBC Connection, forcing the database queries to go to the master server.

                  這種策略允許應用程序將所有只讀流量定向到一組 MySQL 服務器,將所有讀寫流量定向到不同的服務器,而無需更改應用程序的邏輯架構或開發人員不必擔心不同的數據庫主機和角色.

                  This strategy allows the application to direct all read-only traffic to one set of MySQL servers and all read-write traffic to a different server, without changing the application's logical architecture or the developers having to worry about different database hosts and roles.

                  這篇關于Spring/J2EE Apps 中的只讀和讀寫分離的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)

                    <small id='vj6bB'></small><noframes id='vj6bB'>

                      <bdo id='vj6bB'></bdo><ul id='vj6bB'></ul>
                    • <legend id='vj6bB'><style id='vj6bB'><dir id='vj6bB'><q id='vj6bB'></q></dir></style></legend>

                            <tbody id='vj6bB'></tbody>

                            <i id='vj6bB'><tr id='vj6bB'><dt id='vj6bB'><q id='vj6bB'><span id='vj6bB'><b id='vj6bB'><form id='vj6bB'><ins id='vj6bB'></ins><ul id='vj6bB'></ul><sub id='vj6bB'></sub></form><legend id='vj6bB'></legend><bdo id='vj6bB'><pre id='vj6bB'><center id='vj6bB'></center></pre></bdo></b><th id='vj6bB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vj6bB'><tfoot id='vj6bB'></tfoot><dl id='vj6bB'><fieldset id='vj6bB'></fieldset></dl></div>
                            <tfoot id='vj6bB'></tfoot>
                            主站蜘蛛池模板: 免费国产视频在线观看 | 午夜免费福利片 | 农村妇女毛片精品久久久 | 成人在线视频一区 | 亚洲欧美日韩精品久久亚洲区 | 欧美另类视频 | 亚洲国产精品久久久久 | www国产亚洲精品久久网站 | 久草视| xx视频在线 | 精品网站999www| 精品一区二区三区四区 | 天天操天天射天天舔 | 一区二区三区久久久 | 特级特黄特色的免费大片 | 欧美日韩视频在线播放 | 一区天堂| 国产重口老太伦 | 综合久久一区 | 国产精品久久久久久久毛片 | 中文字幕一区二区三区四区五区 | 91超碰caoporn97人人 | 亚洲欧美中文日韩在线v日本 | 国产欧美一区二区三区在线看 | 天堂色综合 | 91福利电影在线观看 | 国产91av视频 | 久草网免费 | 伊人伊人| 亚洲国产精品激情在线观看 | 久久久久国产精品一区三寸 | www.天天操 | 99中文字幕 | 欧美影院| 天天综合干| 日本成人三级电影 | 特黄特色大片免费视频观看 | 亚洲天堂久久 | 四虎最新视频 | 成人精品毛片国产亚洲av十九禁 | 亚洲福利在线观看 |