Merge branch 'v3.0' of https://github.com/mastermc05/dynmap into v3.0

This commit is contained in:
mastermc05 2022-08-08 11:00:35 +03:00
commit 36ea4c3938
6 changed files with 66 additions and 13 deletions

View File

@ -49,6 +49,8 @@ public class MicrosoftSQLMapStorage extends MapStorage {
protected int port;
private static final int POOLSIZE = 5;
private Connection[] cpool = new Connection[POOLSIZE];
private long[] cpoolLastUseTS = new long[POOLSIZE]; // Time when last returned to pool
private static final long IDLE_TIMEOUT = 60000; // Use 60 second timeout
private int cpoolCount = 0;
private static final Charset UTF8 = Charset.forName("UTF-8");
@ -527,12 +529,22 @@ public class MicrosoftSQLMapStorage extends MapStorage {
private Connection getConnection() throws SQLException {
Connection c = null;
synchronized (cpool) {
long now = System.currentTimeMillis();
while (c == null) {
for (int i = 0; i < cpool.length; i++) { // See if available connection
if (cpool[i] != null) { // Found one
c = cpool[i];
cpool[i] = null;
break;
// If in pool too long, close it and move on
if ((now - cpoolLastUseTS[i]) > IDLE_TIMEOUT) {
try { cpool[i].close(); } catch (SQLException x) {}
cpool[i] = null;
cpoolCount--;
}
else { // Else, use the connection
c = cpool[i];
cpool[i] = null;
cpoolLastUseTS[i] = now;
break;
}
}
}
if (c == null) {
@ -565,6 +577,7 @@ public class MicrosoftSQLMapStorage extends MapStorage {
for (int i = 0; i < POOLSIZE; i++) {
if (cpool[i] == null) {
cpool[i] = c;
cpoolLastUseTS[i] = System.currentTimeMillis(); // Record last use time
c = null; // Mark it recovered (no close needed
cpool.notifyAll();
break;

View File

@ -49,6 +49,8 @@ public class MySQLMapStorage extends MapStorage {
protected int port;
private static final int POOLSIZE = 5;
private Connection[] cpool = new Connection[POOLSIZE];
private long[] cpoolLastUseTS = new long[POOLSIZE]; // Time when last returned to pool
private static final long IDLE_TIMEOUT = 60000; // Use 60 second timeout
private int cpoolCount = 0;
private static final Charset UTF8 = Charset.forName("UTF-8");
@ -647,12 +649,22 @@ public class MySQLMapStorage extends MapStorage {
Connection c = null;
if (isShutdown) { throw new StorageShutdownException(); }
synchronized (cpool) {
long now = System.currentTimeMillis();
while (c == null) {
for (int i = 0; i < cpool.length; i++) { // See if available connection
if (cpool[i] != null) { // Found one
c = cpool[i];
cpool[i] = null;
break;
// If in pool too long, close it and move on
if ((now - cpoolLastUseTS[i]) > IDLE_TIMEOUT) {
try { cpool[i].close(); } catch (SQLException x) {}
cpool[i] = null;
cpoolCount--;
}
else { // Else, use the connection
c = cpool[i];
cpool[i] = null;
cpoolLastUseTS[i] = now;
break;
}
}
}
if (c == null) {
@ -685,6 +697,7 @@ public class MySQLMapStorage extends MapStorage {
for (int i = 0; i < POOLSIZE; i++) {
if (cpool[i] == null) {
cpool[i] = c;
cpoolLastUseTS[i] = System.currentTimeMillis(); // Record last use time
c = null; // Mark it recovered (no close needed
cpool.notifyAll();
break;

View File

@ -49,6 +49,8 @@ public class PostgreSQLMapStorage extends MapStorage {
private int port;
private static final int POOLSIZE = 5;
private Connection[] cpool = new Connection[POOLSIZE];
private long[] cpoolLastUseTS = new long[POOLSIZE]; // Time when last returned to pool
private static final long IDLE_TIMEOUT = 60000; // Use 60 second timeout
private int cpoolCount = 0;
private static final Charset UTF8 = Charset.forName("UTF-8");
@ -571,12 +573,22 @@ public class PostgreSQLMapStorage extends MapStorage {
Connection c = null;
if (isShutdown) throw new StorageShutdownException();
synchronized (cpool) {
long now = System.currentTimeMillis();
while (c == null) {
for (int i = 0; i < cpool.length; i++) { // See if available connection
if (cpool[i] != null) { // Found one
c = cpool[i];
cpool[i] = null;
break;
// If in pool too long, close it and move on
if ((now - cpoolLastUseTS[i]) > IDLE_TIMEOUT) {
try { cpool[i].close(); } catch (SQLException x) {}
cpool[i] = null;
cpoolCount--;
}
else { // Else, use the connection
c = cpool[i];
cpool[i] = null;
cpoolLastUseTS[i] = now;
break;
}
}
}
if (c == null) {
@ -608,6 +620,7 @@ public class PostgreSQLMapStorage extends MapStorage {
for (int i = 0; i < POOLSIZE; i++) {
if (cpool[i] == null) {
cpool[i] = c;
cpoolLastUseTS[i] = System.currentTimeMillis(); // Record last use time
c = null; // Mark it recovered (no close needed
cpool.notifyAll();
break;

View File

@ -33,6 +33,8 @@ public class SQLiteMapStorage extends MapStorage {
private String databaseFile;
private static final int POOLSIZE = 1; // SQLite is really not thread safe... 1 at a time works best
private Connection[] cpool = new Connection[POOLSIZE];
private long[] cpoolLastUseTS = new long[POOLSIZE]; // Time when last returned to pool
private static final long IDLE_TIMEOUT = 60000; // Use 60 second timeout
private int cpoolCount = 0;
private static final Charset UTF8 = Charset.forName("UTF-8");
@ -492,11 +494,22 @@ public class SQLiteMapStorage extends MapStorage {
throw new StorageShutdownException();
}
synchronized (cpool) {
long now = System.currentTimeMillis();
while (c == null) {
for (int i = 0; i < cpool.length; i++) { // See if available connection
if (cpool[i] != null) { // Found one
c = cpool[i];
cpool[i] = null;
// If in pool too long, close it and move on
if ((now - cpoolLastUseTS[i]) > IDLE_TIMEOUT) {
try { cpool[i].close(); } catch (SQLException x) {}
cpool[i] = null;
cpoolCount--;
}
else { // Else, use the connection
c = cpool[i];
cpool[i] = null;
cpoolLastUseTS[i] = now;
break;
}
}
}
if (c == null) {
@ -532,6 +545,7 @@ public class SQLiteMapStorage extends MapStorage {
for (int i = 0; i < POOLSIZE; i++) {
if (cpool[i] == null) {
cpool[i] = c;
cpoolLastUseTS[i] = System.currentTimeMillis(); // Record last use time
c = null; // Mark it recovered (no close needed
cpool.notifyAll();
break;

View File

@ -38,7 +38,7 @@ allprojects {
apply plugin: 'java'
group = 'us.dynmap'
version = '3.4'
version = '3.4-SNAPSHOT'
}

View File

@ -25,7 +25,7 @@ allprojects {
apply plugin: 'java'
group = 'us.dynmap'
version = '3.4'
version = '3.4-SNAPSHOT'
}