forked from LogBlock/LogBlock
Catched nullpointer at consumer.
This commit is contained in:
@@ -8,11 +8,11 @@ import java.util.logging.Level;
|
|||||||
public class ClearLog implements Runnable
|
public class ClearLog implements Runnable
|
||||||
{
|
{
|
||||||
private Connection conn;
|
private Connection conn;
|
||||||
|
|
||||||
public ClearLog(Connection conn) {
|
public ClearLog(Connection conn) {
|
||||||
this.conn = conn;
|
this.conn = conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (conn == null)
|
if (conn == null)
|
||||||
|
@@ -14,6 +14,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class Consumer implements Runnable
|
public class Consumer implements Runnable
|
||||||
{
|
{
|
||||||
private LinkedBlockingQueue<BlockRow> bqueue = new LinkedBlockingQueue<BlockRow>();
|
private LinkedBlockingQueue<BlockRow> bqueue = new LinkedBlockingQueue<BlockRow>();
|
||||||
|
private Connection conn = null;
|
||||||
|
|
||||||
public void queueBlock(Player player, Block block, int typeAfter) {
|
public void queueBlock(Player player, Block block, int typeAfter) {
|
||||||
queueBlock(player.getName(), block, 0, typeAfter, (byte)0, null, null);
|
queueBlock(player.getName(), block, 0, typeAfter, (byte)0, null, null);
|
||||||
@@ -47,20 +48,26 @@ public class Consumer implements Runnable
|
|||||||
public int getQueueSize() {
|
public int getQueueSize() {
|
||||||
return bqueue.size();
|
return bqueue.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
Connection conn = null;
|
if (conn == null)
|
||||||
|
try {
|
||||||
|
conn = DriverManager.getConnection("jdbc:jdc:jdcpool");
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
LogBlock.log.severe("[LogBlock Consumer] Can't get a connection");
|
||||||
|
}
|
||||||
|
if (conn == null)
|
||||||
|
return;
|
||||||
Statement state = null;
|
Statement state = null;
|
||||||
BlockRow b;
|
BlockRow b;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (bqueue.size() > 100)
|
if (bqueue.size() > 100)
|
||||||
LogBlock.log.info("[LogBlock Consumer] Queue overloaded. Size: " + bqueue.size());
|
LogBlock.log.info("[LogBlock Consumer] Queue overloaded. Size: " + bqueue.size());
|
||||||
try {
|
try {
|
||||||
conn = DriverManager.getConnection("jdbc:jdc:jdcpool");
|
|
||||||
conn.setAutoCommit(false);
|
conn.setAutoCommit(false);
|
||||||
state = conn.createStatement();
|
state = conn.createStatement();
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
while (count < 1000 && !bqueue.isEmpty() && System.currentTimeMillis() - start < 100) {
|
while (count < 1000 && !bqueue.isEmpty() && (System.currentTimeMillis() - start < 100 || count < 100)) {
|
||||||
b = bqueue.poll();
|
b = bqueue.poll();
|
||||||
if (b == null)
|
if (b == null)
|
||||||
continue;
|
continue;
|
||||||
@@ -83,8 +90,6 @@ public class Consumer implements Runnable
|
|||||||
try {
|
try {
|
||||||
if (state != null)
|
if (state != null)
|
||||||
state.close();
|
state.close();
|
||||||
if (conn != null)
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
LogBlock.log.log(Level.SEVERE, "[LogBlock Consumer] SQL exception on close", ex);
|
LogBlock.log.log(Level.SEVERE, "[LogBlock Consumer] SQL exception on close", ex);
|
||||||
}
|
}
|
||||||
|
@@ -342,7 +342,7 @@ public class LogBlock extends JavaPlugin
|
|||||||
try {
|
try {
|
||||||
return DriverManager.getConnection("jdbc:jdc:jdcpool");
|
return DriverManager.getConnection("jdbc:jdc:jdcpool");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
log.log(Level.SEVERE, "[LogBlock] SQL exception", ex);
|
log.log(Level.SEVERE, "[LogBlock] Can't get a connection", ex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user