Add HikariCP connection pool for MySQL (#86)
* Add HikariCP connection pool for MySQL * Make code more compatible with connection pooling - Remove connection caching in Process/Consumer - Use try-with-resources to make sure Connections always get closed, even in when an Exception occurs. * Disable SSL for MySQL
This commit is contained in:
parent
2d90f9cc08
commit
fc99c24a0a
15 changed files with 157 additions and 200 deletions
|
|
@ -324,9 +324,8 @@ public class LookupCommand {
|
|||
class BasicThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
try (Connection connection = Database.getConnection(true)) {
|
||||
ConfigHandler.lookupThrottle.put(player2.getName(), new Object[] { true, System.currentTimeMillis() });
|
||||
Connection connection = Database.getConnection(true);
|
||||
if (connection != null) {
|
||||
Statement statement = connection.createStatement();
|
||||
String blockdata = ChestTransactionLookup.performLookup(command.getName(), statement, location, player2, p2, finalLimit, false);
|
||||
|
|
@ -339,7 +338,6 @@ public class LookupCommand {
|
|||
Chat.sendComponent(player2, blockdata);
|
||||
}
|
||||
statement.close();
|
||||
connection.close();
|
||||
}
|
||||
else {
|
||||
Chat.sendMessage(player2, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DATABASE_BUSY));
|
||||
|
|
@ -422,9 +420,8 @@ public class LookupCommand {
|
|||
class BasicThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
try (Connection connection = Database.getConnection(true)) {
|
||||
ConfigHandler.lookupThrottle.put(player2.getName(), new Object[] { true, System.currentTimeMillis() });
|
||||
Connection connection = Database.getConnection(true);
|
||||
if (connection != null) {
|
||||
Statement statement = connection.createStatement();
|
||||
if (t == 8) {
|
||||
|
|
@ -461,7 +458,6 @@ public class LookupCommand {
|
|||
}
|
||||
}
|
||||
statement.close();
|
||||
connection.close();
|
||||
}
|
||||
else {
|
||||
Chat.sendMessage(player2, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DATABASE_BUSY));
|
||||
|
|
@ -681,7 +677,7 @@ public class LookupCommand {
|
|||
class BasicThread2 implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
try (Connection connection = Database.getConnection(true)) {
|
||||
ConfigHandler.lookupThrottle.put(player2.getName(), new Object[] { true, System.currentTimeMillis() });
|
||||
|
||||
List<String> uuidList = new ArrayList<>();
|
||||
|
|
@ -699,7 +695,6 @@ public class LookupCommand {
|
|||
ConfigHandler.lookupAlist.put(player2.getName(), finalArgAction);
|
||||
ConfigHandler.lookupRadius.put(player2.getName(), radius);
|
||||
|
||||
Connection connection = Database.getConnection(true);
|
||||
if (connection != null) {
|
||||
Statement statement = connection.createStatement();
|
||||
String baduser = "";
|
||||
|
|
@ -950,7 +945,6 @@ public class LookupCommand {
|
|||
Chat.sendMessage(player2, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.USER_NOT_FOUND, baduser));
|
||||
}
|
||||
statement.close();
|
||||
connection.close();
|
||||
}
|
||||
else {
|
||||
Chat.sendMessage(player2, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DATABASE_BUSY));
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
package net.coreprotect.command;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.*;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
|
@ -94,14 +91,12 @@ public class PurgeCommand extends Consumer {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
try (Connection connection = Database.getConnection(false, 500)) {
|
||||
int timestamp = (int) (System.currentTimeMillis() / 1000L);
|
||||
int ptime = timestamp - seconds;
|
||||
long removed = 0;
|
||||
|
||||
Connection connection = null;
|
||||
for (int i = 0; i <= 5; i++) {
|
||||
connection = Database.getConnection(false, 500);
|
||||
if (connection != null) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -344,8 +339,6 @@ public class PurgeCommand extends Consumer {
|
|||
}
|
||||
}
|
||||
|
||||
connection.close();
|
||||
|
||||
if (abort) {
|
||||
if (!Config.getGlobal().MYSQL) {
|
||||
(new File(ConfigHandler.path + ConfigHandler.sqlite + ".tmp")).delete();
|
||||
|
|
|
|||
|
|
@ -310,11 +310,10 @@ public class RollbackRestoreCommand {
|
|||
class BasicThread2 implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
try (Connection connection = Database.getConnection(false, 1000)) {
|
||||
ConfigHandler.lookupThrottle.put(player.getName(), new Object[] { true, System.currentTimeMillis() });
|
||||
int action = finalAction;
|
||||
Location location = locationFinal;
|
||||
Connection connection = Database.getConnection(false, 1000);
|
||||
if (connection != null) {
|
||||
Statement statement = connection.createStatement();
|
||||
String baduser = "";
|
||||
|
|
@ -407,7 +406,6 @@ public class RollbackRestoreCommand {
|
|||
Chat.sendMessage(player2, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.USER_NOT_FOUND, baduser));
|
||||
}
|
||||
statement.close();
|
||||
connection.close();
|
||||
}
|
||||
else {
|
||||
Chat.sendMessage(player2, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.DATABASE_BUSY));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue