Catched nullpointer at consumer.

This commit is contained in:
Robin Kupper
2011-04-05 00:48:53 +02:00
parent f89434c5d9
commit d805965981
3 changed files with 14 additions and 9 deletions

View File

@@ -8,11 +8,11 @@ import java.util.logging.Level;
public class ClearLog implements Runnable
{
private Connection conn;
public ClearLog(Connection conn) {
this.conn = conn;
}
@Override
public void run() {
if (conn == null)

View File

@@ -14,6 +14,7 @@ import org.bukkit.entity.Player;
public class Consumer implements Runnable
{
private LinkedBlockingQueue<BlockRow> bqueue = new LinkedBlockingQueue<BlockRow>();
private Connection conn = null;
public void queueBlock(Player player, Block block, int typeAfter) {
queueBlock(player.getName(), block, 0, typeAfter, (byte)0, null, null);
@@ -47,20 +48,26 @@ public class Consumer implements Runnable
public int getQueueSize() {
return bqueue.size();
}
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;
BlockRow b;
int count = 0;
if (bqueue.size() > 100)
LogBlock.log.info("[LogBlock Consumer] Queue overloaded. Size: " + bqueue.size());
try {
conn = DriverManager.getConnection("jdbc:jdc:jdcpool");
conn.setAutoCommit(false);
state = conn.createStatement();
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();
if (b == null)
continue;
@@ -83,8 +90,6 @@ public class Consumer implements Runnable
try {
if (state != null)
state.close();
if (conn != null)
conn.close();
} catch (SQLException ex) {
LogBlock.log.log(Level.SEVERE, "[LogBlock Consumer] SQL exception on close", ex);
}

View File

@@ -342,7 +342,7 @@ public class LogBlock extends JavaPlugin
try {
return DriverManager.getConnection("jdbc:jdc:jdcpool");
} catch (SQLException ex) {
log.log(Level.SEVERE, "[LogBlock] SQL exception", ex);
log.log(Level.SEVERE, "[LogBlock] Can't get a connection", ex);
return null;
}
}