久久久久久久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 中的只讀和讀寫分離的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我們?cè)陧?xiàng)目中使用 Spring、Spring-Data 和 JPA.

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

                  對(duì)于生產(chǎn)服務(wù)器,我們希望設(shè)置數(shù)據(jù)庫(kù)集群,以便所有讀取查詢都指向一臺(tái)服務(wù)器,所有寫入查詢都指向另一臺(tái)服務(wù)器.

                  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.

                  這顯然需要對(duì) DAO 的構(gòu)建方式進(jìn)行一些更改.

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

                  如果到目前為止,有人一直使用 Spring-Data/JPA 遵循食譜風(fēng)格的 DAO 創(chuàng)建,其中 DAO 實(shí)現(xiàn)負(fù)責(zé)讀取和寫入,那么有誰知道如何實(shí)現(xiàn)這一點(diǎn)?需要在架構(gòu)上進(jìn)行什么樣的更改來隔離這兩種類型的調(diào)用?

                  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 時(shí),Java 開發(fā)人員通常使用 Connector/J 作為 JDBC 驅(qū)動(dòng)程序.開發(fā)者通常使用Connector/J com.mysql.jdbc.Driver 類,通過諸如jdbc:mysql://host[:port]/database 的URL 來連接到 MySQL 數(shù)據(jù)庫(kù).

                  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 提供了另一個(gè)名為 ReplicationDriver 允許應(yīng)用程序在多個(gè) MySQL 主機(jī)之間進(jìn)行負(fù)載平衡.使用 ReplicationDriver 時(shí),JDBC URL 更改為 jdbc:mysql:replication://master-host[:master-port][,slave-1-host[:slave-1-port]][,slave-2-host[:slave-2-port]]/database.這允許應(yīng)用程序連接到多個(gè)服務(wù)器之一,具體取決于在任何給定時(shí)間點(diǎn)可用的服務(wù)器.

                  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 時(shí),如果 JDBC 連接設(shè)置為 read-only,驅(qū)動(dòng)程序會(huì)將 URL 中聲明的第一個(gè)主機(jī)視為 read-將 主機(jī)和所有其他主機(jī)寫入只讀 主機(jī).開發(fā)人員可以通過如下構(gòu)造他們的代碼在 Spring 應(yīng)用程序中利用這一點(diǎn):

                  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(...) { ... }
                  }
                  

                  這樣的代碼,每當(dāng)readSomething方法被調(diào)用時(shí),Spring事務(wù)管理代碼都會(huì)獲取一個(gè)JDBCConnection并調(diào)用setReadOnly(true)code> 在它上面,因?yàn)榉?wù)方法默認(rèn)使用 @Transactional(readOnly = true) 注釋.這將使來自 readSomething 方法的所有數(shù)據(jù)庫(kù)查詢轉(zhuǎn)到非主 MySQL 主機(jī)之一,以循環(huán)方式進(jìn)行負(fù)載平衡.同樣,每當(dāng)writeSomething被調(diào)用時(shí),Spring都會(huì)在底層的JDBCConnection上調(diào)用setReadOnly(false),強(qiáng)制數(shù)據(jù)庫(kù)查詢到master服務(wù)器.

                  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.

                  這種策略允許應(yīng)用程序?qū)⑺兄蛔x流量定向到一組 MySQL 服務(wù)器,將所有讀寫流量定向到不同的服務(wù)器,而無需更改應(yīng)用程序的邏輯架構(gòu)或開發(fā)人員不必?fù)?dān)心不同的數(shù)據(jù)庫(kù)主機(jī)和角色.

                  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.

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

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

                  相關(guān)文檔推薦

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

                    <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>
                            主站蜘蛛池模板: 国产福利视频导航 | 欧美日韩精品中文字幕 | 一区二区三区欧美 | 一区二区三区四区电影视频在线观看 | 欧美亚洲视频 | 黄色免费在线网址 | 欧美日韩在线一区二区三区 | 久久a久久 | 国产综合第一页 | 在线观看av免费 | 午夜免费福利电影 | 久久精品国产清自在天天线 | 久久69精品久久久久久国产越南 | 91久久精品国产91久久 | 日韩网站免费观看 | 免费色网址 | 精品在线| 欧产日产国产精品视频 | 成人欧美一区二区三区在线播放 | 97国产精品视频人人做人人爱 | 91美女在线观看 | 91久久 | 91免费版在线观看 | 日本精品视频 | 亚洲成人日韩 | 亚洲97| 国产免费一区二区三区 | 亚洲97| 日本精品视频 | 一呦二呦三呦国产精品 | 国产观看| 天天拍天天操 | 91精品国产综合久久福利软件 | 日韩中文字幕 | 蜜桃免费一区二区三区 | 国产精品久久久久久高潮 | 亚洲成人免费 | 久久综合久久综合久久 | 一区二区三区亚洲 | 日本一二区视频 | 欧美区日韩区 |