1

I want to connect tomcat with mysql in a load balanced way.

Is this possible in Tomcat 7?

What changes are required in the following configuration?.

<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/javatest"/> 

i have 2 mysql servers localhost:3306 & secondhost:3306

Thanks

1 Answer 1

1

MySQL manual for Connector/J indicates it's possible.

Note that you need to configure your MySQL servers to replicate with each other (master-master replication). You should use at least MySQL version 5.6, as it has greatly improved replication reliability. It is however still possible that your application will try to read a data row only written recently to one host which is not yet replicated to the other one, especially when under heavy load.

You may get better results with a proper database clustering solution. Have you considered XtraDB Cluster?

3
  • I am looking for the tomcat configuration to achieve this, I can configure master-master replication. Do you know the connection string to use?. Commented Jul 27, 2015 at 10:42
  • Have you checked the link? It is there. Commented Jul 27, 2015 at 10:43
  • 1
    Oh yes. It's there. Thanks. --> jdbc:mysql:loadbalance://[host1][:port],[host2][:port][,[host3][:port]]...[/[database]] » [?propertyName1=propertyValue1[&propertyName2=propertyValue2]...] Commented Jul 27, 2015 at 10:47

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.